package com.cloudhandson.vpdbackoffice.mapper;

import com.cloudhandson.vpdbackoffice.domain.masking.ColumnMaskingRule;
import com.cloudhandson.vpdbackoffice.domain.masking.MaskingRule;
import com.cloudhandson.vpdbackoffice.domain.masking.MaskingRuleCreateCommand;
import com.cloudhandson.vpdbackoffice.domain.masking.MaskingPolicyStatus;
import com.cloudhandson.vpdbackoffice.domain.masking.UserMaskingRule;
import com.cloudhandson.vpdbackoffice.service.MaskingPolicyTarget;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

@Mapper
public interface MaskingRuleMapper {

  List<MaskingRule> findAllRules();

  List<MaskingRule> findEnabledRules();

  MaskingRule findRuleById(@Param("ruleId") long ruleId);

  MaskingRule findRuleByCode(@Param("ruleCode") String ruleCode);

  long nextRuleId();

  void insertRule(@Param("ruleId") long ruleId, @Param("command") MaskingRuleCreateCommand command);

  int updateRuleActive(@Param("ruleId") long ruleId, @Param("enabledYn") String enabledYn);

  List<ColumnMaskingRule> findColumnRules();

  List<MaskingPolicyStatus> findPolicyStatuses(
      @Param("owner") String owner,
      @Param("targets") List<MaskingPolicyTarget> targets
  );

  ColumnMaskingRule findColumnRule(@Param("columnId") long columnId);

  void upsertColumnRule(@Param("columnId") long columnId, @Param("ruleId") long ruleId);

  int deleteColumnRule(@Param("columnId") long columnId);

  int deleteUserRulesForColumn(@Param("columnId") long columnId);

  List<UserMaskingRule> findUserRules();

  UserMaskingRule findUserRule(@Param("userId") long userId, @Param("columnId") long columnId);

  void upsertUserRule(
      @Param("userId") long userId,
      @Param("columnId") long columnId,
      @Param("decision") String decision
  );

  int deleteUserRule(@Param("userId") long userId, @Param("columnId") long columnId);
}
