/** Type definitions for the SIB transportation app */

export type RouteStatus = 'ACTIVE' | 'INACTIVE' | 'MAINTENANCE'
export type StopType = 'TERMINAL' | 'REGULAR' | 'EXPRESS_ONLY'
export type ScheduleType = 'weekday' | 'weekend' | 'holiday'

export interface Route {
    id: string
    name: string
    description?: string
    color: string
    direction: string
    origin_city?: string
    destination_city?: string
    origin_stop_id?: string | null      // ID de la parada donde inicia la ruta
    destination_stop_id?: string | null  // ID de la parada donde finaliza la ruta
    distance_km?: number
    estimated_duration_minutes?: number
    average_speed_kmh?: number
    status: RouteStatus
    created_at?: string
    updated_at?: string
}

export interface BusStop {
    id: string
    name: string
    latitude: number
    longitude: number
    city?: string
    address?: string
    stop_type: StopType
    has_shelter: boolean
    has_seating: boolean
    is_accessible: boolean
    created_at?: string
    updated_at?: string
    // Route-specific fields (from route_stops junction table) OR global order
    stop_order?: number
    travel_time_minutes?: number
    stop_delay_minutes?: number
    is_pickup_point?: boolean
    is_dropoff_point?: boolean
}

export interface RouteStop {
    id: string
    route_id: string
    stop_id: string
    stop_order: number
    travel_time_minutes?: number
    stop_delay_minutes?: number
    is_pickup_point: boolean
    is_dropoff_point: boolean
    created_at?: string
}

export interface BusSchedule {
    id: string
    route_id: string
    departure_time: string
    frequency_minutes?: number
    schedule_type: ScheduleType
    is_active: boolean
    is_published: boolean
    notes?: string
    created_at?: string
}

export interface Coupon {
    id: string
    business_id?: string | null
    title: string
    description?: string | null
    image_url?: string | null
    social_media?: string | null
    terms?: string | null
    discount_percentage?: number | null
    discount_amount?: number | null
    category?: string | null
    valid_from?: string | null
    valid_until?: string | null
    is_active: boolean
    business?: Business | null
    created_at?: string
    updated_at?: string
}

export interface Business {
    id: string
    name: string
    address?: string | null
    phone?: string | null
    image_url?: string | null
    social_media?: string | null
    category?: string | null
    latitude?: number | null
    longitude?: number | null
    area?: string | null
    description?: string | null
    website?: string | null
    // Template/Mold fields
    schedule?: string | null       // "Lun-Sáb 8am-10pm"
    whatsapp?: string | null       // WhatsApp number
    instagram?: string | null      // @handle
    facebook?: string | null       // page URL or username
    gallery_images?: string[]      // carousel photo URLs
    updated_at?: string
}

export type UserCouponStatus = 'claimed' | 'redeemed' | 'expired'

export interface UserCoupon {
    id: string
    user_id: string
    coupon_id: string
    status: UserCouponStatus
    redemption_code: string
    claimed_at: string
    redeemed_at?: string | null
    coupon?: Coupon
}

export interface Taxi {
    id: string
    owner_name: string
    phone_number: string
    license_plate: string
    cooperative?: string
    corregimiento: string
    vehicle_type?: string
    shifts: string[] // Cambiado de 'shift: string' a 'shifts: string[]' para múltiples jornadas
    rating?: number
    english_speaking?: boolean
    is_accessible?: boolean // Facilidad para personas con discapacidad
    image_url?: string
    is_active: boolean
    created_at?: string
    updated_at?: string
}

export interface Favorite {
    id: string
    user_id: string
    item_type: 'coupon' | 'business' | 'taxi' | 'route' | 'stop' | 'shuttle'
    item_id: string
    item_name?: string
    item_image?: string
    created_at?: string
}

export type BusStopCreate = Omit<BusStop, 'id' | 'created_at' | 'updated_at'>
export type BusStopUpdate = Partial<BusStopCreate>

export type RouteCreate = Omit<Route, 'id' | 'created_at' | 'updated_at'>
export type RouteUpdate = Partial<RouteCreate>

export interface RouteStopCreate {
    stop_id: string
    stop_order?: number
    travel_time_minutes?: number
    stop_delay_minutes?: number
    is_pickup_point?: boolean
    is_dropoff_point?: boolean
}

export interface RouteStopUpdate {
    stop_order?: number
    travel_time_minutes?: number
    stop_delay_minutes?: number
    is_pickup_point?: boolean
    is_dropoff_point?: boolean
}

export interface Shuttle {
    id: string
    route_name: string
    description?: string
    origin: string
    destination: string
    vehicle_type: string
    company_name?: string
    trip_type: 'one_way' | 'round_trip' | 'both'
    price_per_person?: number
    price_private_trip?: number
    estimated_duration: string
    departure_times?: string
    contact_whatsapp: string
    phone_number?: string
    english_speaking?: boolean
    image_url?: string
    category?: 'local' | 'interprovincial' | 'all'
    is_active: boolean
    created_at?: string
    updated_at?: string
}
