package com.dayou.brokerage.validator;

import cn.hutool.core.util.StrUtil;
import com.dayou.bo.BrokerageDetailBO;
import com.dayou.brokerage.config.BrokerageConfig;
import com.dayou.brokerage.constants.BrokerageRule;
import com.dayou.brokerage.constants.BrokerageState;
import com.dayou.enums.GlobalConfigEnum;
import com.dayou.exception.ErrorCode;
import com.dayou.service.IGlobalConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ApplicationContext;

import javax.annotation.Nullable;
import java.math.BigDecimal;

/**
 * 类说明：提成校验器
 *
 * @author: wucl
 * @since: 2023/3/3
 * created with IntelliJ IDEA.
 */
@Slf4j
public class BrokerageValidator {

    //校验当月回款是否完成
    public Boolean checkMarketerPredictBrokerage(BigDecimal brokerageCurrent, BigDecimal brokerageTarget){
        if (brokerageCurrent.compareTo(brokerageTarget)== -1){
            log.info(ErrorCode.BROKERAGE_ITEM_STATE_ERROR2.getErrorMsg());
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    /**
     * 项目状态验证（预算）
     * @param brokerageDetailBo
     */
    //校验项目提成状态
    public void checkItemBrokerageStatus(BrokerageDetailBO brokerageDetailBo){
        if (StrUtil.equals(BrokerageRule.LAND_MARKETER_RULE.getCode(),brokerageDetailBo.getBrokerageRule())){
            if (StrUtil.equals(BrokerageState.CLOSED.getCode(),brokerageDetailBo.getMarketerStatus())){
                                    ErrorCode.throwBusinessException(ErrorCode.BROKERAGE_ITEM_STATE_ERROR1);
            }
        }

        if (StrUtil.equals(BrokerageRule.LAND_OTHER_RULE.getCode(),brokerageDetailBo.getBrokerageRule())){
                if (StrUtil.equals(BrokerageState.CLOSED.getCode(),brokerageDetailBo.getParticipantStatus())){
                            ErrorCode.throwBusinessException(ErrorCode.BROKERAGE_ITEM_STATE_ERROR1);
                }
        }
    }

    /**
     * 项目状态验证（预算非市场人员）
     * @param participantStatus
     */
    public void checkItemBrokerageStatusOnParticipantPredict(String participantStatus){
        if (StrUtil.equals(BrokerageState.CLOSED.getCode(),participantStatus)){
            ErrorCode.throwBusinessException(ErrorCode.BROKERAGE_ITEM_STATE_ERROR1);
        }
    }

    /**
     * 项目状态验证（预算市场人员）
     * @param brokerageStatus
     */
    public void checkItemBrokerageStatusOnMarketerPredict(String brokerageStatus){
        if (StrUtil.equals(BrokerageState.CLOSED.getCode(),brokerageStatus)){
            ErrorCode.throwBusinessException(ErrorCode.BROKERAGE_ITEM_STATE_ERROR1);
        }
    }

    /**
     * 项目状态验证（结算非市场人员）
     * @param participantStatus
     */
    public void checkItemBrokerageStatusOnParticipantSettle(String participantStatus){
        if (!StrUtil.equals(BrokerageState.NOT_SETTLE.getCode(),participantStatus)){
            ErrorCode.throwBusinessException(ErrorCode.BROKERAGE_ITEM_STATE_ERROR);
        }
    }

    /**
     * 项目状态验证（结算市场人员）
     * @param brokerageStatus
     */
    public void checkItemBrokerageStatusOnMarketerSettle(String brokerageStatus){
        if (!StrUtil.equals(BrokerageState.NOT_SETTLE.getCode(),brokerageStatus)){
            ErrorCode.throwBusinessException(ErrorCode.BROKERAGE_ITEM_STATE_ERROR);
        }
    }

}
