package com.ruoyi.web.modules.industrypolicy.support;

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyGrantRecord;

@DisplayName("SubsidyGrantRecordValidation merge")
class SubsidyGrantRecordValidationMergeTest
{

    private static final String VALID_ID_CARD = "11010519491231002X";

    @Test
    @DisplayName("与脱敏展示一致的身份证合并")
    void mergeEqualsMaskedIdCard()
    {
        BizSubsidyGrantRecord db = new BizSubsidyGrantRecord();
        db.setIdCard(VALID_ID_CARD);

        BizSubsidyGrantRecord in = new BizSubsidyGrantRecord();
        in.setIdCard(SubsidyGrantRecordMasking.maskIdCard(VALID_ID_CARD));

        SubsidyGrantRecordValidation.mergeSensitiveFieldsForUpdate(in, db);
        assertEquals(VALID_ID_CARD, in.getIdCard());
    }

    @Test
    @DisplayName("全角数字身份证规范化")
    void normalizeFullWidthDigits()
    {
        assertEquals(VALID_ID_CARD, SubsidyGrantRecordValidation.normalizeIdCard("１１０１０５１９４９１２３１００２Ｘ"));
    }

    @Test
    @DisplayName("脱敏身份证合并后可校验通过")
    void mergeMaskedIdCardThenValidate()
    {
        BizSubsidyGrantRecord db = new BizSubsidyGrantRecord();
        db.setIdCard(VALID_ID_CARD);
        db.setContactPhone("13800138000");
        db.setBankAccount("6222021234567890");

        BizSubsidyGrantRecord in = new BizSubsidyGrantRecord();
        in.setIdCard("1101**********002X");
        in.setContactPhone("138****8000");
        in.setBankAccount("************7890");

        SubsidyGrantRecordValidation.mergeSensitiveFieldsForUpdate(in, db);
        assertEquals(VALID_ID_CARD, in.getIdCard());
        assertDoesNotThrow(() -> SubsidyGrantRecordValidation.validateIdCard(in.getIdCard()));
    }
}
