package com.ningdatech.carapi.driver.helper;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ningdatech.carapi.common.constant.VehicleTypeEnum;
import com.ningdatech.carapi.driver.model.bo.CodingRuleBO;
import com.ningdatech.carapi.sys.entity.CodingRule;
import com.ningdatech.carapi.sys.entity.enumeration.CodingRuleBehaviorTypeEnum;
import com.ningdatech.carapi.sys.entity.enumeration.RuleOperationTypeEnum;
import com.ningdatech.carapi.sys.service.ICodingRuleService;
import com.ningdatech.carapi.sys.service.IExamRuleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author liuxinxin
 * @date 2022/11/14 上午11:27
 */
@Component
@RequiredArgsConstructor
public class DriverBehaviorScoreHelper {

    private final IExamRuleService iExamRuleService;
    private final ICodingRuleService iCodingRuleService;

//    public Integer getExamScoreValue() {
//        iExamRuleService.getById()
//    }

    /**
     * 行为类型
     *
     * @param behaviorType
     * @return
     */
    public CodingRuleBO getCodingRuleBehaviorScore(CodingRuleBehaviorTypeEnum behaviorType, VehicleTypeEnum vehicleTypeEnum) {
        CodingRule codingRule = null;
        if (Objects.nonNull(vehicleTypeEnum)) {
            codingRule = iCodingRuleService.getOne(Wrappers.lambdaQuery(CodingRule.class)
                    .eq(CodingRule::getVehicleType, vehicleTypeEnum.name())
                    .eq(CodingRule::getBehaviorType, behaviorType.name()));
        }else {
            codingRule = iCodingRuleService.getOne(Wrappers.lambdaQuery(CodingRule.class)
                    .eq(CodingRule::getBehaviorType, behaviorType.name()));
        }
        Integer operationScore = codingRule.getOperationScore();
        String ruleOperationType = codingRule.getRuleOperationType();

        CodingRuleBO codingRuleBO = new CodingRuleBO();
        codingRuleBO.setOperationScore(operationScore);
        codingRuleBO.setRuleOperationType(RuleOperationTypeEnum.valueOf(ruleOperationType));
        return codingRuleBO;
    }
}
