package com.zhongshu.card.server.core.controller.paySetting;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.projectAbout.PayChannelConfigAllPayModel;
import com.zhongshu.card.client.model.projectAbout.PayChannelConfigModel;
import com.zhongshu.card.client.model.projectAbout.PayChannelConfigParam;
import com.zhongshu.card.client.model.projectAbout.PayChannelConfigSearch;
import com.zhongshu.card.client.type.DataState;
import com.zhongshu.card.server.core.service.paySetting.ProjectChannelConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 项目的支付渠道设置
 *
 * @author TRX
 * @date 2024/7/26
 */
@RestController
@RequestMapping("/projectChannel")
@Tag(name = "支付管理-支付产品")
public class ProjectChannelController {

    @Autowired
    private ProjectChannelConfigService projectChannelConfigService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存支付渠道数据", description = "保存支付渠道数据")
    @RequestMapping(value = "savePayChannelConfig", method = {RequestMethod.POST})
    public ResultContent savePayChannelConfig(@RequestBody PayChannelConfigParam param) {
        return projectChannelConfigService.savePayChannelConfig(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "编辑支付渠道数据", description = "编辑支付渠道数据")
    @RequestMapping(value = "updatePayChannelConfig", method = {RequestMethod.POST})
    public ResultContent updatePayChannelConfig(@RequestBody PayChannelConfigParam param) {
        return projectChannelConfigService.updatePayChannelConfig(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "数据列表-分页查询", description = "数据列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<PayChannelConfigAllPayModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) PayChannelConfigSearch param) {
        return projectChannelConfigService.page(param, pageable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除数据", description = "删除数据")
    @RequestMapping(value = "deleteData", method = {RequestMethod.POST})
    public ResultContent deleteData(@RequestBody IDParam param) {
        return projectChannelConfigService.deleteData(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "数据详情", description = "数据详情")
    @RequestMapping(value = "getDetail", method = {RequestMethod.POST})
    public ResultContent getDetail(@RequestBody IDParam param) {
        return projectChannelConfigService.getDetail(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "启用", description = "启用")
    @RequestMapping(value = "enableData", method = {RequestMethod.POST})
    public ResultContent enableData(@RequestBody IDParam param) {
        return projectChannelConfigService.changeState(param.getId(), DataState.Enable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "禁用", description = "禁用")
    @RequestMapping(value = "disableData", method = {RequestMethod.POST})
    public ResultContent disableData(@RequestBody IDParam param) {
        return projectChannelConfigService.changeState(param.getId(), DataState.Disable);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到所有可用的支付产品", description = "得到所有可用的支付产品")
    @RequestMapping(value = "getPlatFormAllPay", method = {RequestMethod.POST})
    public ResultContent getPlatFormAllPay() {
        return projectChannelConfigService.getPlatFormAllPay();
    }

}
