package com.css.simulation.resource.server.infra.db.mysql.mapper;

import api.common.pojo.param.scene.SceneEvaluationRuleParam;
import api.common.pojo.param.scene.SceneEvaluationScriptParam;
import api.common.pojo.po.scene.SceneEvaluationRulePO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


@Mapper
@Repository
public interface SceneEvaluationRuleMapper {

    void saveSceneEvaluationRule(SceneEvaluationRulePO params);

    void updateSceneEvaluationRule(SceneEvaluationRulePO params);

    List<SceneEvaluationRulePO> querySceneEvaluationRuleList(SceneEvaluationRuleParam params);

    @Select("<script>" +
            "select count(rule_name)\n" +
            "from scene_evaluation_rule\n" +
            "where rule_name = #{ruleName}  AND is_deleted = '0' \n" +
            "<if test='ruleId != null'>" +
            " AND rule_id != #{ruleId}" +
            "</if>" +
            "</script>")
    int querySceneEvaluationRuleOnly(@Param("ruleName") String ruleName, @Param("ruleId") String ruleId);

    List<SceneEvaluationRulePO> queryEvaluationScript(SceneEvaluationScriptParam sceneEvaluationScriptParam);

    @Select("select rule_id, rule_name, rule_type,script_name, script_path\n" +
            "from scene_evaluation_rule\n" +
            "where is_deleted = '0' AND rule_id =  #{ruleId} \n")
    SceneEvaluationRulePO querySceneEvaluationPyById(@Param("ruleId") String ruleId);

}
