//
//  CustomItineraryItem.swift
//  SportsTime
//

import Foundation

struct CustomItineraryItem: Identifiable, Codable, Hashable {
    let id: UUID
    let tripId: UUID
    var category: ItemCategory
    var title: String
    var anchorType: AnchorType
    var anchorId: String?
    var anchorDay: Int
    var sortOrder: Int  // For ordering within same anchor position
    let createdAt: Date
    var modifiedAt: Date

    init(
        id: UUID = UUID(),
        tripId: UUID,
        category: ItemCategory,
        title: String,
        anchorType: AnchorType = .startOfDay,
        anchorId: String? = nil,
        anchorDay: Int,
        sortOrder: Int = 0,
        createdAt: Date = Date(),
        modifiedAt: Date = Date()
    ) {
        self.id = id
        self.tripId = tripId
        self.category = category
        self.title = title
        self.anchorType = anchorType
        self.anchorId = anchorId
        self.anchorDay = anchorDay
        self.sortOrder = sortOrder
        self.createdAt = createdAt
        self.modifiedAt = modifiedAt
    }

    enum ItemCategory: String, Codable, CaseIterable {
        case restaurant
        case hotel
        case activity
        case note

        var icon: String {
            switch self {
            case .restaurant: return "🍽️"
            case .hotel: return "🏨"
            case .activity: return "🎯"
            case .note: return "📝"
            }
        }

        var label: String {
            switch self {
            case .restaurant: return "Restaurant"
            case .hotel: return "Hotel"
            case .activity: return "Activity"
            case .note: return "Note"
            }
        }

        var systemImage: String {
            switch self {
            case .restaurant: return "fork.knife"
            case .hotel: return "bed.double.fill"
            case .activity: return "figure.run"
            case .note: return "note.text"
            }
        }
    }

    enum AnchorType: String, Codable {
        case startOfDay
        case afterGame
        case afterTravel
    }
}
