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

import api.common.pojo.param.scene.ScoringRulesParam;
import api.common.pojo.po.scene.ScoringRulesPO;
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 ScoringRulesMapper {

    void saveScoringRules(ScoringRulesPO params);

    ScoringRulesPO queryScoringRulesByRuleName(ScoringRulesParam params);

    ScoringRulesPO querySelfOnly(@Param("ruleName") String ruleName, @Param("createUserId") String createUserId);

    List<ScoringRulesPO> queryScoringRulesList(ScoringRulesParam params);

    Integer queryCsbById(ScoringRulesParam params);

    ScoringRulesPO queryScoringRules(ScoringRulesParam params);

    void updateScoringRules(ScoringRulesPO params);

    void deleteScoringRules(ScoringRulesPO params);

    @Select("select sr.rules_id\n" +
            "from scoring_rules sr\n" +
            "where sr.is_deleted = '1'\n" +
            "  and sr.rules_id in (select sps.package_and_rules\n" +
            "                      from scene_package_sublist sps\n" +
            "                      where sps.is_deleted = '0' and sps.root_id = #{packageId})")
    List<String> selectDeletedRulesByPackageId(@Param("packageId") String scenePackageId);

    @Select("<script>" +
            "select rule_name\n" +
            "from scoring_rules\n" +
            "where rules_id in \n" +
            "    <foreach item='item' collection='ruleIds' separator=',' open='(' close=')'>\n" +
            "      #{item}\n" +
            "    </foreach>" +
            "</script>")
    List<String> selectRuleNamesByRuleIds(@Param("ruleIds") List<String> ruleIds);

    @Select("select is_deleted from scoring_rules where rules_id = #{ruleId}")
    String selectIsDeletedByRuleId(@Param("ruleId")String ruleId);
}
