import Foundation
import SwiftData

/// A habit within a specific ritual arc. Each arc has its own copy of habits
/// with their own completion tracking, allowing habits to change between arcs
/// while preserving historical data.
@Model
final class ArcHabit {
    var id: UUID = UUID()
    var title: String = ""
    var symbolName: String = ""
    var goal: String = ""
    var completedDayIDs: [String] = []
    
    @Relationship(inverse: \RitualArc.habits)
    var arc: RitualArc?

    init(
        id: UUID = UUID(),
        title: String,
        symbolName: String,
        goal: String = "",
        completedDayIDs: [String] = []
    ) {
        self.id = id
        self.title = title
        self.symbolName = symbolName
        self.goal = goal
        self.completedDayIDs = completedDayIDs
    }
    
    /// Creates a copy of this habit for a new arc (without completions).
    func copyForNewArc() -> ArcHabit {
        ArcHabit(
            title: title,
            symbolName: symbolName,
            goal: goal,
            completedDayIDs: []
        )
    }
}
