package com.ga.core.mapper.rule;

import com.ga.core.vo.rule.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 수수료 규정 Mapper. 5개 테이블을 통합한 인터페이스.
 */
@Mapper
public interface RuleMapper {

    // === commission_rate ===
    List<CommissionRateVO> selectCommissionRates(@Param("productId") Long productId,
                                                 @Param("year") Integer year);
    /** 계약일에 유효한 보험사 수수료율 */
    BigDecimal findCompanyRate(@Param("productId") Long productId,
                               @Param("year") Integer year,
                               @Param("baseDate") LocalDate baseDate);
    int insertCommissionRate(CommissionRateVO vo);
    int updateCommissionRate(CommissionRateVO vo);
    int deleteCommissionRate(@Param("rateId") Long rateId);

    // === payout_rule ===
    List<PayoutRuleVO> selectPayoutRules(@Param("gradeId") Long gradeId,
                                         @Param("insuranceType") String insuranceType);
    BigDecimal findPayoutRate(@Param("gradeId") Long gradeId,
                              @Param("insuranceType") String insuranceType,
                              @Param("year") Integer year,
                              @Param("baseDate") LocalDate baseDate);
    int insertPayoutRule(PayoutRuleVO vo);
    int updatePayoutRule(PayoutRuleVO vo);
    int deletePayoutRule(@Param("ruleId") Long ruleId);

    // === override_rule ===
    List<OverrideRuleVO> selectOverrideRules();
    int insertOverrideRule(OverrideRuleVO vo);
    int updateOverrideRule(OverrideRuleVO vo);
    int deleteOverrideRule(@Param("overrideId") Long overrideId);

    // === chargeback_rule ===
    List<ChargebackRuleVO> selectChargebackRules(@Param("companyCode") String companyCode);
    BigDecimal findChargebackRate(@Param("companyCode") String companyCode,
                                  @Param("insuranceType") String insuranceType,
                                  @Param("lapseMonth") Integer lapseMonth,
                                  @Param("baseDate") LocalDate baseDate);
    int insertChargebackRule(ChargebackRuleVO vo);
    int updateChargebackRule(ChargebackRuleVO vo);
    int deleteChargebackRule(@Param("cbRuleId") Long cbRuleId);

    // === exception_type_code ===
    List<ExceptionTypeCodeVO> selectExceptionCodes();
    ExceptionTypeCodeVO selectExceptionCode(@Param("exceptionCode") String exceptionCode);
    int insertExceptionCode(ExceptionTypeCodeVO vo);
    int updateExceptionCode(ExceptionTypeCodeVO vo);
}
