import Foundation

public struct WordOfDay: Codable, Equatable, Sendable {
    public var spanish: String
    public var english: String
    public var subtitle: String

    public init(spanish: String, english: String, subtitle: String) {
        self.spanish = spanish
        self.english = english
        self.subtitle = subtitle
    }
}

public struct WidgetData: Codable, Equatable, Sendable {
    public var todayCount: Int
    public var dailyGoal: Int
    public var currentStreak: Int
    public var dueCardCount: Int
    public var wordOfTheDay: WordOfDay?
    public var latestTestScore: Int?
    public var latestTestWeek: Int?
    public var currentWeek: Int
    public var lastUpdated: Date

    public init(
        todayCount: Int,
        dailyGoal: Int,
        currentStreak: Int,
        dueCardCount: Int,
        wordOfTheDay: WordOfDay?,
        latestTestScore: Int?,
        latestTestWeek: Int?,
        currentWeek: Int,
        lastUpdated: Date
    ) {
        self.todayCount = todayCount
        self.dailyGoal = dailyGoal
        self.currentStreak = currentStreak
        self.dueCardCount = dueCardCount
        self.wordOfTheDay = wordOfTheDay
        self.latestTestScore = latestTestScore
        self.latestTestWeek = latestTestWeek
        self.currentWeek = currentWeek
        self.lastUpdated = lastUpdated
    }

    public static let placeholder = WidgetData(
        todayCount: 12,
        dailyGoal: 50,
        currentStreak: 3,
        dueCardCount: 8,
        wordOfTheDay: WordOfDay(spanish: "hablar", english: "to speak", subtitle: "Level: Basic"),
        latestTestScore: 85,
        latestTestWeek: 2,
        currentWeek: 2,
        lastUpdated: Date()
    )

    public var progressPercent: Double {
        guard dailyGoal > 0 else { return 0 }
        return min(Double(todayCount) / Double(dailyGoal), 1.0)
    }
}
