import Foundation
import SwiftData

enum PreferredShareAction: String, CaseIterable, Sendable {
    case shareSheet
    case textMessage
    case email

    var localizedTitle: String {
        switch self {
        case .shareSheet: "Share"
        case .textMessage: "Text"
        case .email: "Email"
        }
    }
}

enum DefaultFollowUpPreset: String, CaseIterable, Sendable {
    case none
    case oneWeek
    case twoWeeks

    var localizedTitle: String {
        switch self {
        case .none: "Off"
        case .oneWeek: "1W"
        case .twoWeeks: "2W"
        }
    }

    func followUpDate(from referenceDate: Date) -> Date? {
        switch self {
        case .none:
            nil
        case .oneWeek:
            Calendar.current.date(byAdding: .day, value: 7, to: referenceDate)
        case .twoWeeks:
            Calendar.current.date(byAdding: .day, value: 14, to: referenceDate)
        }
    }
}

@Model
final class AppSettings {
    var id: UUID
    var preferredShareActionRawValue: String
    var defaultFollowUpPresetRawValue: String
    var createdAt: Date
    var updatedAt: Date

    init(
        id: UUID = UUID(),
        preferredShareActionRawValue: String = PreferredShareAction.shareSheet.rawValue,
        defaultFollowUpPresetRawValue: String = DefaultFollowUpPreset.none.rawValue,
        createdAt: Date = .now,
        updatedAt: Date = .now
    ) {
        self.id = id
        self.preferredShareActionRawValue = preferredShareActionRawValue
        self.defaultFollowUpPresetRawValue = defaultFollowUpPresetRawValue
        self.createdAt = createdAt
        self.updatedAt = updatedAt
    }
}
