import Foundation
import Combine

// MARK: - OnboardingStep

/// Each phase of the first-launch onboarding flow.
enum OnboardingStep: Int, CaseIterable {
    case profile  = 0    // Profilangaben
    case contacts = 1    // Kontakte importieren
    case complete = 2
}

// MARK: - OnboardingCoordinator

/// Observable coordinator that owns all onboarding data and drives step transitions.
@MainActor
final class OnboardingCoordinator: ObservableObject {

    // MARK: – Navigation state

    @Published var currentStep: OnboardingStep = .profile

    // MARK: – Phase 1: Profile

    @Published var firstName: String   = ""
    @Published var displayName: String = ""
    @Published var aboutMe: String     = ""
    @Published var gender: String      = ""

    // MARK: – Phase 2: Contacts

    @Published var selectedContacts: [NahbarContact] = []

    // MARK: – Validation

    /// `true` when at least a non-empty first name has been entered.
    var isProfileValid: Bool {
        !firstName.trimmingCharacters(in: .whitespaces).isEmpty
    }

    // MARK: – Navigation actions

    /// Advances to the contact import phase. Validates profile first.
    func advanceToContacts() {
        guard isProfileValid else { return }
        currentStep = .contacts
    }

    /// Marks onboarding as fully complete.
    func completeOnboarding() {
        currentStep = .complete
    }
}
