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

import com.github.microservice.types.payment.PaymentChannelType;
import com.github.microservice.types.payment.PaymentType;
import com.zhongshu.card.client.type.paySetting.RegularType;
import com.zhongshu.card.client.type.paySetting.SettlementRulesType;
import com.zhongshu.card.client.type.paySetting.WithdrawMethodType;
import com.zhongshu.card.client.type.paySetting.WithdrawType;
import com.zhongshu.card.server.core.domain.base.SuperMain;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

import java.math.BigDecimal;

/**
 * 项目主支付配置
 *
 * @author TRX
 * @date 2024/11/4
 */
@Data
@Builder
@Document
@AllArgsConstructor
@NoArgsConstructor
public class ProjectMainPaySetting extends SuperMain {

    @Schema(description = "所属主账户信息")
    @DBRef(lazy = true)
    private ProjectOrgPaySettingInfo paySettingInfo;

    @Schema(description = "所属机构oid")
    private String belongOig;

    @Schema(description = "所属机构名称")
    private String belongOrgName;

    @Schema(description = "所属主账户二级信息")
    @DBRef(lazy = true)
    private ProjectOrgPaySettingInfo childPaySettingInfo;

    @Indexed
    @Schema(description = "项目的支付渠道设置：微信支付、银联支付")
    private PaymentType channelType;

    @Schema(description = "支付产品")
    private PaymentChannelType paymentChannelType;

    //----------------------- 结算规则 start -----------------

    @Schema(description = "结算规则")
    private SettlementRulesType settlementRulesType;

    //---------------D+N结算 设置
    @Schema(description = "天数，>= 1")
    private Integer days;

    @Schema(description = "d+N的时间")
    private String dnTimeStr;

    //---------------定期结算 设置

    @Schema(description = "定期类型")
    private RegularType regularType;

    @Schema(description = "定期结算时间")
    private String regularTimeStr;

    @Schema(description = "当前的时间，如：12:30")
    private String timeStr;

    public String getTimeStr() {
        if (settlementRulesType != null) {
            if (settlementRulesType == SettlementRulesType.Dn) {
                return dnTimeStr;
            } else if (settlementRulesType == SettlementRulesType.Regular) {
                return regularTimeStr;
            }
        }
        return "";
    }

    //----------------------------提现规则 start --------------

    @Schema(description = "提现规则类型")
    private WithdrawType withdrawType;

    @Schema(description = "提现方式")
    private WithdrawMethodType withdrawMethodType;

    @Schema(description = "最小的提现额度")
    private Long minWithdraw = 0L;

    @Schema(description = "最大的提现额度")
    private Long maxWithdraw = 0L;

    //---------------------------分账规则配置 start ------------
    @Schema(description = "最小分账金额, 单位分")
    private Long minSharing = 0L;

    @Schema(description = "全局项目分账比例，0-100")
    private BigDecimal projectScale = BigDecimal.ZERO;

    @Schema(description = "全局机构分账比例，0-100")
    private BigDecimal orgScale = BigDecimal.ZERO;

    @Schema(description = "锁过期时间")
    private Long expireAt;

    @Schema(description = "锁token")
    private String token;

}
