package com.social.media.application.analytics.dto;

import com.social.media.domain.analytics.aggregate.AnalyticsReport;
import com.social.media.domain.analytics.valueobject.ReportType;
import com.social.media.domain.analytics.valueobject.MetricType;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * Analytics Response DTO with Builder pattern
 */
public class AnalyticsResponseDto {
    
    private final String analyticsId;
    private final String companyId;
    private final ReportType reportType;
    private final MetricType metricType;
    private final LocalDateTime periodStart;
    private final LocalDateTime periodEnd;
    private final Map<String, Object> data;
    private final String title;
    private final String description;
    private final LocalDateTime generatedAt;
    private final LocalDateTime createdAt;
    private final LocalDateTime updatedAt;
    
    private AnalyticsResponseDto(Builder builder) {
        this.analyticsId = builder.analyticsId;
        this.companyId = builder.companyId;
        this.reportType = builder.reportType;
        this.metricType = builder.metricType;
        this.periodStart = builder.periodStart;
        this.periodEnd = builder.periodEnd;
        this.data = builder.data;
        this.title = builder.title;
        this.description = builder.description;
        this.generatedAt = builder.generatedAt;
        this.createdAt = builder.createdAt;
        this.updatedAt = builder.updatedAt;
    }
    
    public static Builder builder() {
        return new Builder();
    }
    
    public static Builder builder(AnalyticsReport analyticsReport) {
        return new Builder()
            .analyticsId(analyticsReport.getId().getValue())
            .companyId(analyticsReport.getCompanyId().value().toString())
            .reportType(analyticsReport.getReportType())
            .metricType(analyticsReport.getMetricType())
            .periodStart(analyticsReport.getPeriodStart())
            .periodEnd(analyticsReport.getPeriodEnd())
            .data(analyticsReport.getData())
            .title(analyticsReport.getTitle())
            .description(analyticsReport.getDescription())
            .generatedAt(analyticsReport.getGeneratedAt())
            .createdAt(analyticsReport.getCreatedAt())
            .updatedAt(analyticsReport.getUpdatedAt());
    }
    
    public static class Builder {
        private String analyticsId;
        private String companyId;
        private ReportType reportType;
        private MetricType metricType;
        private LocalDateTime periodStart;
        private LocalDateTime periodEnd;
        private Map<String, Object> data;
        private String title;
        private String description;
        private LocalDateTime generatedAt;
        private LocalDateTime createdAt;
        private LocalDateTime updatedAt;
        
        public Builder analyticsId(String analyticsId) {
            this.analyticsId = analyticsId;
            return this;
        }
        
        public Builder companyId(String companyId) {
            this.companyId = companyId;
            return this;
        }
        
        public Builder reportType(ReportType reportType) {
            this.reportType = reportType;
            return this;
        }
        
        public Builder metricType(MetricType metricType) {
            this.metricType = metricType;
            return this;
        }
        
        public Builder periodStart(LocalDateTime periodStart) {
            this.periodStart = periodStart;
            return this;
        }
        
        public Builder periodEnd(LocalDateTime periodEnd) {
            this.periodEnd = periodEnd;
            return this;
        }
        
        public Builder data(Map<String, Object> data) {
            this.data = data;
            return this;
        }
        
        public Builder title(String title) {
            this.title = title;
            return this;
        }
        
        public Builder description(String description) {
            this.description = description;
            return this;
        }
        
        public Builder generatedAt(LocalDateTime generatedAt) {
            this.generatedAt = generatedAt;
            return this;
        }
        
        public Builder createdAt(LocalDateTime createdAt) {
            this.createdAt = createdAt;
            return this;
        }
        
        public Builder updatedAt(LocalDateTime updatedAt) {
            this.updatedAt = updatedAt;
            return this;
        }
        
        public AnalyticsResponseDto build() {
            return new AnalyticsResponseDto(this);
        }
    }
    
    // Getters
    public String getAnalyticsId() { return analyticsId; }
    public String getCompanyId() { return companyId; }
    public ReportType getReportType() { return reportType; }
    public MetricType getMetricType() { return metricType; }
    public LocalDateTime getPeriodStart() { return periodStart; }
    public LocalDateTime getPeriodEnd() { return periodEnd; }
    public Map<String, Object> getData() { return data; }
    public String getTitle() { return title; }
    public String getDescription() { return description; }
    public LocalDateTime getGeneratedAt() { return generatedAt; }
    public LocalDateTime getCreatedAt() { return createdAt; }
    public LocalDateTime getUpdatedAt() { return updatedAt; }
}

