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

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

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.web.modules.trading.domain.BizDistributor;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

@DisplayName("DistributorValidation")
class DistributorValidationTest
{
    private static final String VALID_ID_CARD = "11010519491231002X";

    private static final String VALID_USCC = "91110000MA01234567";

    private static final String VALID_PHONE = "13800138000";

    @Test
    @DisplayName("承销商名称长度")
    void distributorName()
    {
        assertThrows(ServiceException.class, () -> DistributorValidation.validateDistributorName(""));
        assertDoesNotThrow(() -> DistributorValidation.validateDistributorName("扎西承销商"));
    }

    @Test
    @DisplayName("销售去向枚举")
    void salesDestination()
    {
        assertDoesNotThrow(() -> DistributorValidation.validateSalesDestination(1));
        assertDoesNotThrow(() -> DistributorValidation.validateSalesDestination(3));
        assertThrows(ServiceException.class, () -> DistributorValidation.validateSalesDestination(4));
    }

    @Test
    @DisplayName("个体户身份证")
    void individualIdCard()
    {
        assertDoesNotThrow(() -> DistributorValidation.validateIdentityNo(VALID_ID_CARD, DistributorRules.TYPE_INDIVIDUAL));
        assertThrows(ServiceException.class,
                () -> DistributorValidation.validateIdentityNo("123", DistributorRules.TYPE_INDIVIDUAL));
    }

    @Test
    @DisplayName("企业统一社会信用代码")
    void enterpriseUscc()
    {
        assertDoesNotThrow(() -> DistributorValidation.validateIdentityNo(VALID_USCC, DistributorRules.TYPE_ENTERPRISE));
    }

    @Test
    @DisplayName("销售去向中文名")
    void salesDestinationName()
    {
        assertEquals("本市", DistributorRules.salesDestinationName(1));
        assertEquals("外省", DistributorRules.salesDestinationName(3));
    }

    private static BizDistributor sampleRow()
    {
        BizDistributor r = new BizDistributor();
        r.setDistributorName("扎西承销商");
        r.setDistributorType(DistributorRules.TYPE_INDIVIDUAL);
        r.setIdentityNo(VALID_ID_CARD);
        r.setContactPhone(VALID_PHONE);
        r.setSalesDestination(DistributorRules.SALES_DESTINATION_LOCAL_CITY);
        return r;
    }
}
