package com.ycwl.basic.product.dto;

import com.ycwl.basic.product.capability.ProductTypeCapability;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 商品类型能力配置响应DTO
 */
@Data
public class ProductTypeCapabilityResponse {

    private Long id;
    private String productType;
    private String displayName;
    private String category;
    private String categoryDescription;

    // 定价相关
    private String pricingMode;
    private String pricingModeDescription;
    private Boolean supportsTierPricing;

    // 购买限制
    private Boolean allowDuplicatePurchase;
    private String duplicateCheckStrategy;
    private String duplicateCheckStrategyDescription;

    // 优惠能力
    private Boolean canUseCoupon;
    private Boolean canUseVoucher;
    private Boolean canUseOnePrice;
    private Boolean canUseBundle;

    // 扩展属性
    private Map<String, Object> metadata;
    private Boolean isActive;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;

    /**
     * 从实体转换为响应DTO
     */
    public static ProductTypeCapabilityResponse fromEntity(ProductTypeCapability entity) {
        if (entity == null) {
            return null;
        }

        ProductTypeCapabilityResponse response = new ProductTypeCapabilityResponse();
        response.setId(entity.getId());
        response.setProductType(entity.getProductType());
        response.setDisplayName(entity.getDisplayName());
        response.setCategory(entity.getCategory());

        // 定价相关
        response.setPricingMode(entity.getPricingMode());
        if (entity.getPricingModeEnum() != null) {
            response.setPricingModeDescription(entity.getPricingModeEnum().getDescription());
        }
        response.setSupportsTierPricing(entity.getSupportsTierPricing());

        // 购买限制
        response.setAllowDuplicatePurchase(entity.getAllowDuplicatePurchase());
        response.setDuplicateCheckStrategy(entity.getDuplicateCheckStrategy());
        if (entity.getDuplicateCheckStrategyEnum() != null) {
            response.setDuplicateCheckStrategyDescription(entity.getDuplicateCheckStrategyEnum().getDescription());
        }

        // 优惠能力
        response.setCanUseCoupon(entity.getCanUseCoupon());
        response.setCanUseVoucher(entity.getCanUseVoucher());
        response.setCanUseOnePrice(entity.getCanUseOnePrice());
        response.setCanUseBundle(entity.getCanUseBundle());

        // 扩展属性
        response.setMetadata(entity.getMetadata());
        response.setIsActive(entity.getIsActive());
        response.setCreatedAt(entity.getCreatedAt());
        response.setUpdatedAt(entity.getUpdatedAt());

        return response;
    }
}
