package com.erp.tenant.dto;

import com.erp.tenant.entity.Package;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 套餐响应DTO
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PackageResponse {
    
    private Long id;
    private String name;
    private String code;
    private String type;
    private String typeLabel;
    private BigDecimal price;
    private Integer periodDays;
    private Integer sort;
    private Boolean isDefault;
    private Integer trialDays;
    private Integer status;
    private String statusLabel;
    private String features;
    private String limits;
    private String remark;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    
    /**
     * 从实体转换为响应DTO
     */
    public static PackageResponse fromEntity(Package pkg) {
        if (pkg == null) {
            return null;
        }
        
        return PackageResponse.builder()
                .id(pkg.getId())
                .name(pkg.getName())
                .code(pkg.getCode())
                .type(pkg.getType())
                .typeLabel(pkg.getTypeLabel())
                .price(pkg.getPrice())
                .periodDays(pkg.getPeriodDays())
                .sort(pkg.getSort())
                .isDefault(pkg.getIsDefault())
                .trialDays(pkg.getTrialDays())
                .status(pkg.getStatus())
                .statusLabel(pkg.isActive() ? "启用" : "禁用")
                .features(pkg.getFeatures())
                .limits(pkg.getLimits())
                .remark(pkg.getRemark())
                .createdAt(pkg.getCreatedAt())
                .updatedAt(pkg.getUpdatedAt())
                .build();
    }
}
