package com.ruoyi.ccdi.project.mapper;

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

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

class CcdiProjectOverviewMapperRiskModelCardsTest {

    @Test
    void shouldExposeRiskModelCardsMapperMethod() throws Exception {
        Method method = CcdiProjectOverviewMapper.class.getMethod("selectRiskModelCardsByProjectId", Long.class);
        assertNotNull(method);
    }

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

        assertTrue(xml.contains("<select id=\"selectRiskModelCardsByProjectId\""));
        assertTrue(xml.contains("from ccdi_project_overview_employee_result"));
        assertTrue(xml.contains("from ccdi_bank_tag_rule"));
        assertTrue(xml.contains("where enabled = 1"));
        assertTrue(xml.contains("left join ("));
        assertTrue(xml.contains("model_hit_summary_json"));
        assertTrue(xml.contains("json_extract("));
        assertTrue(xml.contains("coalesce(stats.warning_count, 0) as warning_count"));
        assertTrue(xml.contains("coalesce(stats.people_count, 0) as people_count"));
        assertTrue(xml.contains(".warningCount"));
        assertTrue(xml.contains("order by warning_count desc, model_code asc"));
    }
}
