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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.entry.dto.EntryApplyShopDTO;
import com.ruoyi.web.modules.entry.dto.EntryApplySubmitDTO;
import com.ruoyi.web.modules.merchant.constant.MerchantConstants;
import com.ruoyi.web.modules.merchant.domain.BizMerchant;

/**
 * 申请表单映射测试（MEA-UT）
 */
class EntryApplyFormMapperTest
{
    @Test
    void toFormJson_andParse_roundTrip()
    {
        EntryApplySubmitDTO dto = new EntryApplySubmitDTO();
        dto.setAgreementAccepted(true);
        BizMerchant subject = new BizMerchant();
        subject.setMerchantType(MerchantConstants.TYPE_PERSON);
        subject.setPersonName("张三");
        dto.setSubject(subject);
        BizMerchant biz = new BizMerchant();
        biz.setMerchantName("张三店");
        dto.setBiz(biz);
        EntryApplyShopDTO shop = new EntryApplyShopDTO();
        shop.setShopName("旗舰店");
        dto.setShop(shop);

        String json = EntryApplyFormMapper.toFormJson(dto);
        assertNotNull(json);

        EntryApplyFormMapper.ParsedForm parsed = EntryApplyFormMapper.parseFormJson(json);
        assertEquals("张三", parsed.getSubject().getPersonName());
        assertEquals("张三店", parsed.getBiz().getMerchantName());
        assertEquals("旗舰店", parsed.getShop().getShopName());
        assertEquals(true, parsed.getAgreementAccepted());
    }

    @Test
    void resolveSubjectLabel_person()
    {
        BizMerchant subject = new BizMerchant();
        subject.setPersonName("张三");
        assertEquals("张三", EntryApplyFormMapper.resolveSubjectLabel(MerchantConstants.TYPE_PERSON, subject));
    }

    @Test
    void resolveSubjectLabel_enterprise()
    {
        BizMerchant subject = new BizMerchant();
        subject.setCompanyName("测试企业");
        assertEquals("测试企业",
                EntryApplyFormMapper.resolveSubjectLabel(MerchantConstants.TYPE_ENTERPRISE, subject));
    }
}
