package com.hotwj.platform.pay.controller;

import java.util.List;

import com.hotwj.platform.pay.domain.bo.PayChannelBo;
import com.hotwj.platform.pay.domain.vo.PayChannelVo;
import com.hotwj.platform.pay.service.IPayChannelService;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;

/**
 * 支付渠道
 *
 * @author shihongwei
 * @date 2026-05-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/platform/channel")
@Tag(name = "支付渠道", description = "支付渠道管理")
public class PayChannelController extends BaseController {

    private final IPayChannelService payChannelService;

    /**
     * 查询支付渠道列表
     */
    @SaCheckPermission("platform:channel:list")
    @GetMapping("/list")
    @Operation(summary = "分页查询支付渠道列表")
    public TableDataInfo<PayChannelVo> list(PayChannelBo bo, PageQuery pageQuery) {
        return payChannelService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出支付渠道列表
     */
    @SaCheckPermission("platform:channel:export")
    @Log(title = "支付渠道 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出支付渠道列表")
    public void export(PayChannelBo bo, HttpServletResponse response) {
        List<PayChannelVo> list = payChannelService.queryList(bo);
        ExcelUtil.exportExcel(list, "支付渠道", PayChannelVo.class, response);
    }

    /**
     * 获取支付渠道详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("platform:channel:query")
    @GetMapping("/{id}")
    @Operation(summary = "获取支付渠道详细信息")
    public R<PayChannelVo> getInfo(@NotNull(message = "主键不能为空")
                                   @Parameter(name = "id", description = "主键", required = true, example = "1")
                                   @PathVariable Long id) {
        return R.ok(payChannelService.queryById(id));
    }

    /**
     * 新增支付渠道
     */
    @SaCheckPermission("platform:channel:add")
    @Log(title = "支付渠道", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    @Operation(summary = "新增支付渠道")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PayChannelBo bo) {
        return toAjax(payChannelService.insertByBo(bo));
    }

    /**
     * 修改支付渠道
     */
    @SaCheckPermission("platform:channel:edit")
    @Log(title = "支付渠道", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    @Operation(summary = "修改支付渠道")
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PayChannelBo bo) {
        return toAjax(payChannelService.updateByBo(bo));
    }

    /**
     * 删除支付渠道
     *
     * @param ids 主键串
     */
    @SaCheckPermission("platform:channel:remove")
    @Log(title = "支付渠道", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @Operation(summary = "删除支付渠道")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @Parameter(name = "ids", description = "主键串", required = true, example = "1,2,3")
                          @PathVariable Long[] ids) {
        return toAjax(payChannelService.deleteWithValidByIds(List.of(ids), true));
    }
}
