import Foundation

/// A draft is a recipe, not a copy of video data: an ordered list of
/// instructions referencing source clip IDs. Duplicating one costs ~nothing.
struct Draft: Identifiable, Codable, Equatable, Hashable {
    let id: UUID
    var name: String
    var createdAt: Date
    var modifiedAt: Date
    var clips: [DraftClip]

    var totalDuration: Double {
        clips.reduce(0) { $0 + $1.segmentDuration }
    }
}

/// One timeline entry. The same source clip can appear multiple times, so this
/// has its own instance ID separate from the source ID it points at.
struct DraftClip: Identifiable, Codable, Equatable, Hashable {
    let id: UUID
    var sourceClipID: UUID
    /// Trim points in seconds into the source clip.
    var trimStart: Double
    var trimEnd: Double
    var isMuted: Bool
    var volume: Double
    var textOverlays: [TextOverlay]

    var segmentDuration: Double { max(0, trimEnd - trimStart) }
}

struct TextOverlay: Identifiable, Codable, Equatable, Hashable {
    let id: UUID
    var text: String
    /// Normalized 0–1 position in render space; 0.5/0.5 is centered.
    var posX: Double
    var posY: Double
    var fontSize: Double
    var hasBackground: Bool

    static func centered(_ text: String = "Text") -> TextOverlay {
        TextOverlay(id: UUID(), text: text, posX: 0.5, posY: 0.5, fontSize: 32, hasBackground: false)
    }
}
