package com.seer.teach.pay.admin.pay.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.ResultBean;
import com.seer.teach.common.annotation.LogPrint;
import com.seer.teach.pay.admin.pay.controller.req.AdminPayChannelSaveReq;
import com.seer.teach.pay.admin.pay.controller.req.AdminPayChannelUpdateReq;
import com.seer.teach.pay.admin.pay.controller.resp.PayChannelResp;
import com.seer.teach.pay.admin.pay.service.AdminPayChannelService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.NotNull;
import java.util.List;

@RequestMapping("/pay/channel")
@RestController
@Tag(name = "管理端 - 支付渠道")
@Validated
@RequiredArgsConstructor
public class AdminPayChannelController {

    private final AdminPayChannelService payChannelService;


    @GetMapping("/list")
    @Operation(summary = "获取支付渠道列表")
    @LogPrint
    @SaCheckPermission("admin:pay:channel:list")
    public ResultBean<List<PayChannelResp>> getPayChannelList(){
        List<PayChannelResp> payChannelRespList = payChannelService.getPayChannelList();
        return ResultBean.success(payChannelRespList);
    }

    @PostMapping("/save")
    @Operation(summary = "新增支付渠道")
    @LogPrint
    @SaCheckPermission("admin:pay:channel:save")
    public ResultBean addPayChannel(@RequestBody @Validated AdminPayChannelSaveReq params){
        payChannelService.addPayChannel(params);
        return ResultBean.success();
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除支付渠道")
    @LogPrint
    @SaCheckPermission("admin:pay:channel:delete")
    public ResultBean deletePayChannel(@PathVariable("id") @NotNull(message = "支付渠道ID不可为空") Integer id){
        payChannelService.deletePayChannel(id);
        return ResultBean.success();
    }

    @GetMapping("/{id}")
    @Operation(summary = "获取支付渠道详情")
    @LogPrint
    @SaCheckPermission("admin:pay:channel:detail")
    public ResultBean<PayChannelResp> getPayChannelDetail(@PathVariable("id") @NotNull(message = "支付渠道ID不可为空") Integer id){
        PayChannelResp payChannelResp = payChannelService.getPayChannelDetail(id);
        return ResultBean.success(payChannelResp);
    }

    @PostMapping("/update/{id}")
    @Operation(summary = "修改支付渠道")
    @LogPrint
    @SaCheckPermission("admin:pay:channel:update")
    public ResultBean updatePayChannel(@PathVariable("id") @NotNull(message = "支付渠道ID不可为空") Integer id,
            @RequestBody @Validated AdminPayChannelUpdateReq params){
        payChannelService.updatePayChannel(id,params);
        return ResultBean.success();
    }
}
