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

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.seer.teach.common.PageListBean;
import com.seer.teach.common.ResultBean;
import com.seer.teach.pay.admin.withdrawal.controller.request.PayWithdrawalConfigPageReq;
import com.seer.teach.pay.admin.withdrawal.controller.request.PayWithdrawalConfigReq;
import com.seer.teach.pay.admin.withdrawal.controller.response.PayWithdrawalConfigResp;
import com.seer.teach.pay.admin.sys.service.AdminPayWithdrawalConfigService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * PayWithdrawalConfig控制器
 *
 * @author ZS
 * @since 2025-09-17
 */
@RestController
@RequestMapping("/pay/withdrawal/config")
@Tag(name = "管理端 - 提现规则配置管理")
public class AdminPayWithdrawalConfigController {

    @Autowired
    private AdminPayWithdrawalConfigService payWithdrawalConfigService;

    @PostMapping("/paged")
    @Operation(summary = "分页查询提现规则配置")
    @SaCheckPermission("admin:pay:withdrawal:config:page")
    public ResultBean<PageListBean<PayWithdrawalConfigResp>> pageList(@Parameter(description = "分页查询参数") @RequestBody PayWithdrawalConfigPageReq queryParam) {
        return ResultBean.success(payWithdrawalConfigService.pageList(queryParam));
    }

    @PostMapping("/list")
    @Operation(summary = "获取提现规则配置列表")
    @SaCheckPermission("admin:pay:withdrawal:config:list")
    public ResultBean<List<PayWithdrawalConfigResp>> list(@Parameter(description = "查询参数") @RequestBody PayWithdrawalConfigReq payWithdrawalConfig) {
        return ResultBean.success(payWithdrawalConfigService.list(payWithdrawalConfig));
    }

    @GetMapping("/{id}")
    @Operation(summary = "根据ID获取提现规则配置")
    @SaCheckPermission("admin:pay:withdrawal:config:detail")
    public ResultBean<PayWithdrawalConfigResp> getById(@Parameter(description = "ID") @PathVariable Long id) {
        return ResultBean.success(payWithdrawalConfigService.getDetail(id));
    }

    @PostMapping
    @Operation(summary = "新增提现规则配置")
    @SaCheckPermission("admin:pay:withdrawal:config:create")
    public ResultBean<Boolean> save(@Parameter(description = "新增参数") @RequestBody PayWithdrawalConfigReq payWithdrawalConfig) {
        return ResultBean.success(payWithdrawalConfigService.save(payWithdrawalConfig));
    }

    @PutMapping
    @Operation(summary = "更新提现规则配置")
    @SaCheckPermission("admin:pay:withdrawal:config:update")
    public ResultBean<Boolean> update(@Parameter(description = "更新参数") @RequestBody PayWithdrawalConfigReq payWithdrawalConfig) {
        return ResultBean.success(payWithdrawalConfigService.updateById(payWithdrawalConfig));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除提现规则配置")
    @SaCheckPermission("admin:pay:withdrawal:config:delete")
    public ResultBean<Boolean> delete(@Parameter(description = "ID") @PathVariable Integer id) {
        return ResultBean.success(payWithdrawalConfigService.deleteById(id));
    }
}