//
//  MoonPhase.swift
//  Shared between MoonWatch and MoonWatchWidget.
//

import Foundation

public enum MoonPhaseName: String, CaseIterable, Sendable {
    case newMoon = "New Moon"
    case waxingCrescent = "Waxing Crescent"
    case firstQuarter = "First Quarter"
    case waxingGibbous = "Waxing Gibbous"
    case fullMoon = "Full Moon"
    case waningGibbous = "Waning Gibbous"
    case thirdQuarter = "Third Quarter"
    case waningCrescent = "Waning Crescent"
}

public struct MoonPhaseSnapshot: Equatable, Sendable {
    public let date: Date
    /// Position in synodic month, 0 at new moon approaching 1 at the next new moon.
    public let normalizedPhase: Double
    /// Days since last new moon, in `[0, synodicMonth)`.
    public let moonAgeDays: Double
    public let namedPhase: MoonPhaseName
    /// Fraction of the apparent disk illuminated, 0…1.
    public let illuminatedFraction: Double
    /// The next phase that will begin after the current one.
    public let nextPhaseName: MoonPhaseName
    /// Days until the next phase transition.
    public let daysToNextPhase: Double

    public init(
        date: Date,
        normalizedPhase: Double,
        moonAgeDays: Double,
        namedPhase: MoonPhaseName,
        illuminatedFraction: Double,
        nextPhaseName: MoonPhaseName,
        daysToNextPhase: Double
    ) {
        self.date = date
        self.normalizedPhase = normalizedPhase
        self.moonAgeDays = moonAgeDays
        self.namedPhase = namedPhase
        self.illuminatedFraction = illuminatedFraction
        self.nextPhaseName = nextPhaseName
        self.daysToNextPhase = daysToNextPhase
    }
}
