package com.erp.supplier.dto.response;

import com.erp.supplier.entity.ProcurementInquiry;
import lombok.Data;
import lombok.Builder;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Builder
public class ProcurementInquiryResponse {

    private Long id;
    private String inquiryNo;
    private Long supplierId;
    private String supplierName;
    private String inquiryType;
    private String inquiryTypeText;
    private Long productId;
    private String productName;
    private String productSpec;
    private String unit;
    private BigDecimal quantity;
    private String expectedDeliveryDate;
    private String inquiryStatus;
    private String inquiryStatusText;
    private LocalDateTime inquiryDate;
    private String quoteDeadline;
    private BigDecimal quotedPrice;
    private String currency;
    private String quoteValidUntil;
    private Integer deliveryCycle;
    private String qualityStandard;
    private String paymentTerms;
    private String remark;
    private Integer isSelected;
    private String selectionReason;
    private Long creatorId;
    private String creatorName;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;

    public static ProcurementInquiryResponse fromEntity(ProcurementInquiry inquiry) {
        return ProcurementInquiryResponse.builder()
                .id(inquiry.getId())
                .inquiryNo(inquiry.getInquiryNo())
                .supplierId(inquiry.getSupplierId())
                .supplierName(inquiry.getSupplierName())
                .inquiryType(inquiry.getInquiryType())
                .inquiryTypeText(getInquiryTypeText(inquiry.getInquiryType()))
                .productId(inquiry.getProductId())
                .productName(inquiry.getProductName())
                .productSpec(inquiry.getProductSpec())
                .unit(inquiry.getUnit())
                .quantity(inquiry.getQuantity())
                .expectedDeliveryDate(inquiry.getExpectedDeliveryDate())
                .inquiryStatus(inquiry.getInquiryStatus())
                .inquiryStatusText(getInquiryStatusText(inquiry.getInquiryStatus()))
                .inquiryDate(inquiry.getInquiryDate())
                .quoteDeadline(inquiry.getQuoteDeadline())
                .quotedPrice(inquiry.getQuotedPrice())
                .currency(inquiry.getCurrency())
                .quoteValidUntil(inquiry.getQuoteValidUntil())
                .deliveryCycle(inquiry.getDeliveryCycle())
                .qualityStandard(inquiry.getQualityStandard())
                .paymentTerms(inquiry.getPaymentTerms())
                .remark(inquiry.getRemark())
                .isSelected(inquiry.getIsSelected())
                .selectionReason(inquiry.getSelectionReason())
                .creatorId(inquiry.getCreatorId())
                .creatorName(inquiry.getCreatorName())
                .createdAt(inquiry.getCreatedAt())
                .updatedAt(inquiry.getUpdatedAt())
                .build();
    }

    public static String getInquiryTypeText(String type) {
        if (type == null) return "";
        switch (type) {
            case "product": return "商品询价";
            case "material": return "原材料询价";
            case "service": return "服务询价";
            default: return type;
        }
    }

    public static String getInquiryStatusText(String status) {
        if (status == null) return "";
        switch (status) {
            case "draft": return "草稿";
            case "sent": return "已发送";
            case "replied": return "已报价";
            case "compared": return "已比价";
            case "confirmed": return "已确认";
            case "cancelled": return "已取消";
            default: return status;
        }
    }
}
