package com.ycwl.basic.pricing.service;

import com.ycwl.basic.pricing.entity.PriceProductConfig;
import com.ycwl.basic.pricing.entity.PriceTierConfig;
import com.ycwl.basic.pricing.enums.ProductType;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

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

/**
 * Default配置校验测试
 */
class DefaultConfigValidationTest {

    @Test
    void testDefaultProductConfigValidation() {
        // 测试default商品配置的创建校验逻辑
        PriceProductConfig config = new PriceProductConfig();
        config.setProductType(ProductType.PHOTO_PRINT.getCode());
        config.setProductId("default");
        config.setProductName("默认打印配置");
        config.setBasePrice(new BigDecimal("5.00"));
        config.setOriginalPrice(new BigDecimal("8.00"));
        config.setUnit("元/张");
        config.setIsActive(true);
        
        // 验证productId为default
        assertEquals("default", config.getProductId());
        assertEquals(ProductType.PHOTO_PRINT.getCode(), config.getProductType());
        
        System.out.println("Default商品配置创建成功: " + config.getProductName());
    }
    
    @Test
    void testDefaultTierConfigCreation() {
        // 测试default阶梯配置的创建
        PriceTierConfig config = new PriceTierConfig();
        config.setProductType(ProductType.PHOTO_PRINT.getCode());
        config.setProductId("default");
        config.setMinQuantity(1);
        config.setMaxQuantity(10);
        config.setPrice(new BigDecimal("5.00"));
        config.setOriginalPrice(new BigDecimal("8.00"));
        config.setUnit("元/张");
        config.setSortOrder(1);
        config.setIsActive(true);
        
        // 验证productId为default
        assertEquals("default", config.getProductId());
        assertEquals(ProductType.PHOTO_PRINT.getCode(), config.getProductType());
        
        System.out.println("Default阶梯配置创建成功: " + config.getProductType() + 
                ", 数量区间: " + config.getMinQuantity() + "-" + config.getMaxQuantity());
    }
    
    @Test
    void testProductIdFallbackLogic() {
        // 测试兜底逻辑的概念验证
        String specificProductId = "video_001";
        String fallbackProductId = "default";
        
        // 模拟查询特定商品失败，需要使用default配置
        boolean specificFound = false; // 假设没有找到特定配置
        String actualProductId = specificFound ? specificProductId : fallbackProductId;
        
        assertEquals("default", actualProductId);
        System.out.println("使用兜底配置: productId=" + actualProductId);
    }
}