package com.erp.supplier.dto.response;

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

@Data
@Builder
public class SupplierRatingResponse {

    private Long id;
    private Long supplierId;
    private String supplierName;
    private String ratingPeriod;
    private String ratingPeriodText;
    private Integer ratingYear;
    private Integer ratingMonth;
    private BigDecimal qualityScore;
    private BigDecimal deliveryScore;
    private BigDecimal priceScore;
    private BigDecimal serviceScore;
    private BigDecimal overallScore;
    private String grade;
    private String gradeText;
    private Long evaluatorId;
    private String evaluatorName;
    private LocalDateTime evaluationTime;
    private String strengths;
    private String weaknesses;
    private String suggestions;
    private String remark;
    private LocalDateTime createdAt;

    public static SupplierRatingResponse fromEntity(SupplierRating rating) {
        return SupplierRatingResponse.builder()
                .id(rating.getId())
                .supplierId(rating.getSupplierId())
                .ratingPeriod(rating.getRatingPeriod())
                .ratingPeriodText(getRatingPeriodText(rating.getRatingPeriod()))
                .ratingYear(rating.getRatingYear())
                .ratingMonth(rating.getRatingMonth())
                .qualityScore(rating.getQualityScore())
                .deliveryScore(rating.getDeliveryScore())
                .priceScore(rating.getPriceScore())
                .serviceScore(rating.getServiceScore())
                .overallScore(rating.getOverallScore())
                .grade(rating.getGrade())
                .gradeText(getGradeText(rating.getGrade()))
                .evaluatorId(rating.getEvaluatorId())
                .evaluatorName(rating.getEvaluatorName())
                .evaluationTime(rating.getEvaluationTime())
                .strengths(rating.getStrengths())
                .weaknesses(rating.getWeaknesses())
                .suggestions(rating.getSuggestions())
                .remark(rating.getRemark())
                .createdAt(rating.getCreatedAt())
                .build();
    }

    public static String getRatingPeriodText(String period) {
        if (period == null) return "";
        switch (period) {
            case "monthly": return "月度评价";
            case "quarterly": return "季度评价";
            case "annual": return "年度评价";
            default: return period;
        }
    }

    public static String getGradeText(String grade) {
        if (grade == null) return "";
        switch (grade) {
            case "A": return "A级(优秀)";
            case "B": return "B级(良好)";
            case "C": return "C级(一般)";
            case "D": return "D级(较差)";
            default: return grade;
        }
    }
}
