package com.ruoyi.ccdi.project.mapper;

import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CcdiProjectSpecialCheckMapperDetailSqlTest {

    @Test
    void shouldBuildFamilyAssetLiabilityDetailStructureFromProjectScope() throws Exception {
        String xml = Files.readString(Path.of("src/main/resources/mapper/ccdi/project/CcdiProjectSpecialCheckMapper.xml"));

        assertTrue(xml.contains("select id=\"selectFamilyAssetLiabilityDetail\""));
        assertTrue(xml.contains("select id=\"selectFamilyAssetItemsByScope\""));
        assertTrue(xml.contains("select id=\"selectFamilyDebtItemsByScope\""));
        assertTrue(xml.contains("scope.staff_id_card = #{staffIdCard}"));
        assertTrue(xml.contains("spouseIsStaff=spouse_is_staff"));
        assertTrue(xml.contains("relation.relation_cert_no as person_id"));
        assertTrue(xml.contains("spouse_staff.annual_income"));
        assertTrue(xml.contains("spouse.spouse_is_staff = 1"));
        assertTrue(xml.contains("asset.family_id = spouse.spouse_id_card"));
        assertTrue(xml.contains("source.spouse_staff_asset_record_count = 0"));
        assertTrue(xml.contains("source.spouse_staff_debt_record_count = 0"));
        assertTrue(xml.contains("incomeDetail"));
        assertTrue(xml.contains("assetDetail"));
        assertTrue(xml.contains("debtDetail"));
        assertTrue(xml.contains("summary"));
        assertTrue(xml.contains("self_total_asset"));
        assertTrue(xml.contains("spouse_total_asset"));
        assertTrue(xml.contains("self_total_debt"));
        assertTrue(xml.contains("spouse_total_debt"));
        assertTrue(xml.contains("asset_missing_self_asset_info"));
        assertTrue(xml.contains("debt_missing_self_debt_info"));
        assertTrue(xml.contains("asset_name"));
        assertTrue(xml.contains("asset_main_type"));
        assertTrue(xml.contains("asset_sub_type"));
        assertTrue(xml.contains("holder_name"));
        assertTrue(xml.contains("holder_staff.name"));
        assertTrue(xml.contains("select max(relation.relation_name)"));
        assertTrue(xml.contains("relation.relation_cert_no = asset.person_id"));
        assertTrue(xml.contains("current_value"));
        assertTrue(xml.contains("valuation_date"));
        assertTrue(xml.contains("debt_name"));
        assertTrue(xml.contains("debt_main_type"));
        assertTrue(xml.contains("debt_sub_type"));
        assertTrue(xml.contains("creditor_type"));
        assertTrue(xml.contains("owner_name"));
        assertTrue(xml.contains("owner_staff.name"));
        assertTrue(xml.contains("relation.relation_cert_no = debt.person_id"));
        assertTrue(xml.contains("principal_balance"));
        assertTrue(xml.contains("query_date"));
        assertFalse(xml.contains("ccdi_project_overview_employee_result"));
    }
}
