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.base.ProjectOidParam;
import com.zhongshu.card.client.model.paySetting.paySetting.*;
import com.zhongshu.card.client.model.payment.PaymentTypeParam;
import com.zhongshu.card.server.core.service.paySetting.ProjectMainPaySettingService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
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;

import javax.validation.Valid;
import java.util.List;

/**
 * 项目的配置 (结算、提现、分账)
 *
 * @author TRX
 * @date 2024/7/26
 */
@RestController
@RequestMapping("/project/mainPaySetting")
@Tag(name = "项目-配置")
public class ProjectMainPaySettingController {

    @Autowired
    private ProjectMainPaySettingService projectMainPaySettingService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存项目配置", description = "保存项目配置")
    @RequestMapping(value = "saveMainPaySetting", method = {RequestMethod.POST})
    public ResultContent saveMainPaySetting(
            @RequestBody @Valid ProjectMainPaySettingParam param) {
        return projectMainPaySettingService.saveMainPaySetting(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到项目配置", description = "得到项目配置")
    @RequestMapping(value = "getMainPaySetting", method = {RequestMethod.POST})
    public ResultContent<ProjectMainPaySettingModel> getMainPaySetting(
            @RequestBody PaymentTypeParam param) {
        if (param.getPaymentType() == null) {
            return ResultContent.buildFail("paymentType不能为空");
        }
        return projectMainPaySettingService.getMainPaySetting(param.getProjectOid(), param.getPaymentType());
    }

    //------------------------------灵活分账规则 start ------------------------
    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存项目的灵活分账规则", description = "保存项目的灵活分账规则")
    @RequestMapping(value = "savePayShareList", method = {RequestMethod.POST})
    public ResultContent savePayShareList(
            @RequestBody @Valid PayShareListParam param) {
        return projectMainPaySettingService.savePayShareList(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到项目的灵活分账规则列表", description = "得到项目的灵活分账规则列表")
    @RequestMapping(value = "getPayShareList", method = {RequestMethod.POST})
    public ResultContent<List<PayShareListModel>> getPayShareList(
            @RequestBody @Valid PaymentTypeParam param) {
        if (param.getPaymentType() == null) {
            return ResultContent.buildFail("paymentType不能为空");
        }
        return projectMainPaySettingService.getPayShareList(param.getProjectOid(), param.getPaymentType());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除项目的灵活分账规则", description = "删除项目的灵活分账规则")
    @RequestMapping(value = "deletePayShareList", method = {RequestMethod.POST})
    public ResultContent deletePayShareList(
            @RequestBody @Valid IDParam param) {
        return projectMainPaySettingService.deletePayShareList(param.getId());
    }
}
