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

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.modules.merchant.constant.MerchantConstants;
import com.ruoyi.web.modules.merchant.domain.BizMerchant;

class BizCompleteEvaluatorTest
{
    @Test
    void person_withoutBiz_incomplete()
    {
        BizMerchant m = new BizMerchant();
        m.setMerchantType(MerchantConstants.TYPE_PERSON);
        assertEquals(MerchantConstants.BIZ_INCOMPLETE, BizCompleteEvaluator.evaluateCompleteFlag(m));
        assertFalse(BizCompleteEvaluator.pendingFields(m).isEmpty());
    }

    @Test
    void person_withAllBiz_complete()
    {
        BizMerchant m = fullPerson();
        assertEquals(MerchantConstants.BIZ_COMPLETE, BizCompleteEvaluator.evaluateCompleteFlag(m));
        assertTrue(BizCompleteEvaluator.pendingFields(m).isEmpty());
    }

    @Test
    void enterprise_missingLicense_incomplete()
    {
        BizMerchant m = fullPerson();
        m.setMerchantType(MerchantConstants.TYPE_ENTERPRISE);
        m.setBusinessLicense(null);
        m.setAccountPermit(null);
        assertEquals(MerchantConstants.BIZ_INCOMPLETE, BizCompleteEvaluator.evaluateCompleteFlag(m));
        assertTrue(BizCompleteEvaluator.pendingFields(m).contains("营业执照电子版"));
    }

    @Test
    void bizRegion_requiresCodeAndName()
    {
        BizMerchant m = fullPerson();
        m.setBizRegionCode("110");
        m.setBizRegionName(null);
        assertTrue(BizCompleteEvaluator.pendingFields(m).contains("经营地址"));
    }

    private BizMerchant fullPerson()
    {
        BizMerchant m = new BizMerchant();
        m.setMerchantType(MerchantConstants.TYPE_PERSON);
        m.setMerchantName("张三农资");
        m.setServicePhone("400-800");
        m.setBizRegionCode("110");
        m.setBizRegionName("北京");
        m.setBizDetailAddress("路1号");
        m.setContactName("张三");
        m.setContactPhone("13800138000");
        m.setContactEmail("a@b.com");
        m.setBankName("工行");
        m.setBankBranch("支行");
        m.setBankAccount("6222021234567890");
        return m;
    }
}
