package kz.konturai.parser.dto;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.List;
import java.util.Map;


@Data
public class MarketingAnalysisV3Result {

    @JsonProperty("0_executive_summary")
    private ExecutiveSummary executiveSummary;

    @JsonProperty("1_market_landscape")
    private MarketLandscape marketLandscape;

    @JsonProperty("2_geo_structure")
    private GeoStructure geoStructure;

    @JsonProperty("3_competitor_map")
    private List<CompetitorProfile> competitorMap;

    @JsonProperty("4_content_profile")
    private ContentProfile contentProfile;

    @JsonProperty("5_competition_intensity")
    private CompetitionIntensity competitionIntensity;

    @JsonProperty("6_reputation_analysis")
    private ReputationAnalysis reputationAnalysis;

    @JsonProperty("7_behavioral_pattern")
    private BehavioralPattern behavioralPattern;

    @JsonProperty("8_search_demand")
    private SearchDemand searchDemand;

    @JsonProperty("9_user_positioning")
    private UserPositioning userPositioning;

    @JsonProperty("10_structured_conclusions")
    private List<String> structuredConclusions;

    @JsonProperty("11_smm_strategy_rationale")
    private String smmStrategyRationale;

    // ==========================================================

    @Data
    public static class ExecutiveSummary {
        private String businessStage    = "";
        private String geography        = "";
        private int    activeCompetitors = 0;
        private String competitionLevel = "";
        private double averageNicheEr   = 0.0;
        private double averageRating    = 0.0;
        private String demandTrend      = "";
        private List<String> keyFigures = List.of();
    }

    @Data
    public static class MarketLandscape {
        private Map<String, Integer> activePlayersByPlatform = Map.of();
        private Map<String, Integer> cityDistribution        = Map.of();
        private double nicheReputationLevel = 0.0;
    }

    @Data
    public static class GeoStructure {
        private List<CityMetrics> cityComparison = List.of();
        private double densityIndex = 0.0;
    }

    @Data
    public static class CityMetrics {
        private String city            = "";
        private int    activePlayers   = 0;
        private double avgEr           = 0.0;
        private double avgRating       = 0.0;
        private int    avgPostsPerMonth = 0;
    }

    @Data
    public static class CompetitorProfile {
        private String name             = "";
        private String platform         = "";
        private String profileUrl       = "";
        private int    followers        = 0;
        private int    postsPerMonth    = 0;
        private double er               = 0.0;
        private double rating           = 0.0;
        private int    reviews          = 0;
        private String contentStyle     = "";
        private String lastActiveDate   = "";
        private List<String> strengths  = List.of();
        private List<String> weaknesses = List.of();
    }

    @Data
    public static class ContentProfile {
        private double demoContentPercent       = 0.0;
        private double expertContentPercent     = 0.0;
        private double salesContentPercent      = 0.0;
        private double reviewsContentPercent    = 0.0;
        private double engagementContentPercent = 0.0;
        private double videoShare               = 0.0;
        private int    avgTextLengthCharacters  = 0;
        private double ctaUsagePercent          = 0.0;
        private List<String> topHashtags        = List.of();
        private String bestPostingTime          = "";
    }

    @Data
    public static class CompetitionIntensity {
        private int    ciiIndex              = 0;
        private String intensityLabel        = "";
        private List<String> contributingFactors = List.of();
    }

    @Data
    public static class ReputationAnalysis {
        private double avgNicheRating              = 0.0;
        private int    medianReviews               = 0;
        private Map<String, Double> starDistribution = Map.of();
        private double highTrustBusinessShare      = 0.0;
        private int    avgOwnerResponseTimeHours   = 0;
        private List<String> topComplaintThemes    = List.of();
        private List<String> topPraiseThemes       = List.of();
    }

    @Data
    public static class BehavioralPattern {
        private double promoUsagePercent      = 0.0;
        private double directBookingPercent   = 0.0;
        private double priceVisibilityPercent = 0.0;
        private int    avgCycleDays           = 0;
        private List<String> commonCta        = List.of();
    }

    @Data
    public static class SearchDemand {
        private int    avgMonthlySearches         = 0;
        private String trendDirection              = "";
        private double yoyGrowthPercent            = 0.0;
        private List<TimeSeriesPoint> seasonality  = List.of();
        private List<String> peakPeriods           = List.of();
        private List<String> relatedQueries        = List.of();
    }

    @Data
    public static class UserPositioning {
        private RadarMetrics marketMetrics  = new RadarMetrics();
        private RadarMetrics userMetrics    = new RadarMetrics();
        private RadarMetrics gap            = new RadarMetrics();
        private String mode                 = "BENCHMARK";
        private List<String> strategicFocus = List.of();
    }

    @Data
    public static class RadarMetrics {
        private int activity   = 0;
        private int engagement = 0;
        private int video      = 0;
        private int reputation = 0;
        private int frequency  = 0;
    }

    @Data
    public static class TimeSeriesPoint {
        private String period = "";
        private double value  = 0.0;
    }
}