package kz.konturai.parser.model;

import kz.konturai.parser.dto.StatusHistoryEntry;
import lombok.*;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
@Document(collection = "marketing_strategy")
public class MarketingStrategy {

    @Id
    private String id;

    @Field("analysis_id")
    private String analysisId;

    @Field("status")
    private String status; // queued, processing, completed, failed

    // ── Стратегическая модель (добавлено) ────────────────────────────────────
    /** Техническое имя: ENTRY | AUTHORITY | TRUST | CONVERSION */
    @Field("scoring_model_name")
    private String scoringModelName;

    /** Читаемое название для фронта: "Entry — Вход / Формирование присутствия" */
    @Field("scoring_model_title")
    private String scoringModelTitle;
    // ─────────────────────────────────────────────────────────────────────────

    @Field("duration_weeks")
    private Integer durationWeeks;

    @Field("priority_platforms")
    private List<String> priorityPlatforms;

    @Field("weekly_plans")
    private List<WeeklyPlan> weeklyPlans;

    @Field("post_calendar")
    private List<PostCalendarItem> postCalendar;

    @Field("created_at")
    private LocalDateTime createdAt;

    @Field("completed_at")
    private LocalDateTime completedAt;

    @Field("strategy_data")
    private Map<String, Object> strategyData;

    @Field("user_id")
    private String userId;

    @Field("status_history")
    private List<StatusHistoryEntry> statusHistory;

    public MarketingStrategy() {
        this.createdAt = LocalDateTime.now();
        this.status = "queued";
        this.statusHistory = new ArrayList<>();
    }

    public MarketingStrategy(String analysisId) {
        this();
        this.analysisId = analysisId;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class WeeklyPlan {
        @Field("week_number")
        private Integer weekNumber;

        @Field("main_themes")
        private List<String> mainThemes;

        @Field("content_recommendations")
        private String contentRecommendations;

        @Field("priority_platforms")
        private List<String> priorityPlatforms;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class PostCalendarItem {
        @Field("publish_date")
        private LocalDateTime publishDate;

        @Field("week_number")
        private Integer weekNumber;

        @Field("platform")
        private String platform;

        @Field("content_type")
        private String contentType;

        @Field("theme")
        private String theme;

        @Field("post_text")
        private String postText;

        @Field("hashtags")
        private List<String> hashtags;

        @Field("publish_time")
        private String publishTime;

        @Field("image_url")
        private String imageUrl;

        @Field("image_filename")
        private String imageFilename;

        @Field("video_url")
        private String videoUrl;

        @Field("video_filename")
        private String videoFilename;

        @Field("video_generation_prompt")
        private String videoGenerationPrompt;
    }
}