import Foundation

// MARK: - TriggerMode

/// Controls when a tour is automatically started.
enum TriggerMode: Hashable {
    /// Started explicitly by app code; never auto-started by checkForPendingTours().
    case manualOrFirstLaunch
    /// Auto-started when the app version advances past `minAppVersion` and tour hasn't been seen.
    case autoOnUpdate
    /// Never auto-started; only via explicit `TourCoordinator.start(_:)` call.
    case manualOnly
}

// MARK: - Tour

/// Metadata and steps for a single guided tour. Max 6 steps is enforced by precondition.
struct Tour: Identifiable, Hashable {
    let id: TourID
    let title: LocalizedStringResource
    let steps: [TourStep]
    /// Semantic version string, e.g. "1.0". Used for update-tour gating.
    let minAppVersion: String
    let triggerMode: TriggerMode

    init(
        id: TourID,
        title: LocalizedStringResource,
        steps: [TourStep],
        minAppVersion: String,
        triggerMode: TriggerMode
    ) {
        precondition(!steps.isEmpty, "A tour must have at least 1 step.")
        precondition(steps.count <= 8, "A tour must not exceed 8 steps. Got \(steps.count).")
        self.id = id
        self.title = title
        self.steps = steps
        self.minAppVersion = minAppVersion
        self.triggerMode = triggerMode
    }

    // Equatable / Hashable based on id
    static func == (lhs: Tour, rhs: Tour) -> Bool { lhs.id == rhs.id }
    func hash(into hasher: inout Hasher) { hasher.combine(id) }
}
