//
//  WidgetModels.swift
//  ReflectWidget
//
//  Data models for widget timeline entries
//

import WidgetKit
import SwiftUI
import Intents

// MARK: - Timeline View Model

class WatchTimelineView: Identifiable {
    let id = UUID()
    let image: Image
    let graphic: Image
    let date: Date
    let color: Color
    let secondaryColor: Color
    let mood: Mood

    init(image: Image, graphic: Image, date: Date, color: Color, secondaryColor: Color, mood: Mood) {
        self.image = image
        self.date = date
        self.color = color
        self.graphic = graphic
        self.secondaryColor = secondaryColor
        self.mood = mood
    }
}

// MARK: - Timeline Widget Entry

struct SimpleEntry: TimelineEntry {
    let date: Date
    let configuration: ConfigurationIntent
    let timeLineViews: [WatchTimelineView]?
    let showStats: Bool
    let hasSubscription: Bool
    let hasVotedToday: Bool
    let promptText: String

    init(date: Date, configuration: ConfigurationIntent, timeLineViews: [WatchTimelineView]?, showStats: Bool = false, hasSubscription: Bool = false, hasVotedToday: Bool = true, promptText: String = "") {
        self.date = date
        self.configuration = configuration
        self.timeLineViews = timeLineViews
        self.showStats = showStats
        self.hasSubscription = hasSubscription
        self.hasVotedToday = hasVotedToday
        self.promptText = promptText
    }
}

// MARK: - Vote Widget Entry

struct VoteWidgetEntry: TimelineEntry {
    let date: Date
    let votingDate: Date
    let hasSubscription: Bool
    let hasVotedToday: Bool
    let todaysMood: Mood?
    let stats: MoodStats?
    let promptText: String
}

// MARK: - Mood Stats

struct MoodStats {
    let totalEntries: Int
    let moodCounts: [Mood: Int]

    func percentage(for mood: Mood) -> Double {
        guard totalEntries > 0 else { return 0 }
        return Double(moodCounts[mood, default: 0]) / Double(totalEntries) * 100
    }
}
