package com.gxwebsoft.credit.controller;

import com.gxwebsoft.credit.entity.CreditXgxf;
import com.gxwebsoft.credit.param.CreditXgxfImportParam;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

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

class CreditXgxfImportMappingTest {

    private static CreditXgxf convert(CreditXgxfImportParam param) throws Exception {
        CreditXgxfController controller = new CreditXgxfController();
        Method m = CreditXgxfController.class.getDeclaredMethod("convertImportParamToEntity", CreditXgxfImportParam.class);
        m.setAccessible(true);
        return (CreditXgxf) m.invoke(controller, param);
    }

    @Test
    void mapsAlternateUpstreamHeadersForParties() throws Exception {
        CreditXgxfImportParam param = new CreditXgxfImportParam();
        param.setCaseNumber("（2024）示例案号");
        param.setPlaintiffAppellant2("申请执行人A");
        param.setAppellee2("被执行人B");
        param.setCourtName2("执行法院C");

        CreditXgxf entity = convert(param);
        assertEquals("申请执行人A", entity.getPlaintiffAppellant());
        assertEquals("被执行人B", entity.getAppellee());
        assertEquals("执行法院C", entity.getCourtName());
    }

    @Test
    void prefersCanonicalHeadersWhenBothPresent() throws Exception {
        CreditXgxfImportParam param = new CreditXgxfImportParam();
        param.setCaseNumber("（2024）示例案号");
        param.setPlaintiffAppellant("原告A");
        param.setPlaintiffAppellant2("申请执行人A");
        param.setAppellee("被告B");
        param.setAppellee2("被执行人B");
        param.setCourtName("法院C");
        param.setCourtName2("执行法院C");

        CreditXgxf entity = convert(param);
        assertEquals("原告A", entity.getPlaintiffAppellant());
        assertEquals("被告B", entity.getAppellee());
        assertEquals("法院C", entity.getCourtName());
    }
}

