import type { ServiceTypeValue } from './service-types';

export * from "./validation";

export interface Option {
  label: string;
  value: string;
  icon?: React.ComponentType<{ className?: string }>;
  withCount?: boolean;
}

// AI Suggestions Types
export interface AISuggestion {
  placeId: string;
  name: string;
  type: string;
  description?: string;
  reason: string;
  suggestedTimeBlock: 'dawn' | 'morning' | 'afternoon' | 'evening';
  image?: string;
}

// Free Time Block Types
export interface FreeTimeBlock {
  timeBlock: 'dawn' | 'morning' | 'afternoon' | 'evening';
  startTime: string; // HH:MM format
  endTime: string; // HH:MM format
  durationMinutes: number;
}

// Existing Place Context for AI
export interface ExistingPlaceContext {
  placeId: string;
  name: string;
  lat: number;
  lng: number;
  duration: string;
  order_index: number;
}

// Tour Types
export interface Tour {
  id: string;
  destination: string;
  name: string;
  type: ServiceTypeValue;
  covers: string[];
  description?: string;
  duration_hours: number;
  price_from: number;
  price_currency: string;
  commission_rate: number;
  provider_id?: string;
  image_url?: string;
  includes?: string[];
  excludes?: string[];
  meeting_point?: string;
  max_participants?: number;
  min_participants?: number;
  available_days?: string[];
  rating?: number;
  review_count?: number;
  is_active: boolean;
  created_at: string;
  updated_at: string;
}

// Traveler Profile
export interface TravelerProfile {
  group_type: 'couple' | 'family' | 'friends' | 'solo';
  pace: 'slow' | 'balanced' | 'fast';
  budget_level: 'low' | 'mid' | 'high';
}

// Comparison Metrics
export interface ComparisonMetrics {
  distance_saved_km: number;
  time_saved_hours: number;
  logistics_removed: string[];
  expert_value: string[];
}

// Recommendation Display Metadata (provided by AI)
export interface RecommendationDisplayMetadata {
  service_type_label: string; // e.g., "Günlük Tur"
  service_type_icon?: string; // e.g., "🗓️"
  group_label?: string; // e.g., "Önerilen Turlar"
  group_description?: string; // e.g., "Bu günü bireysel gezmek yerine..."
  segment_message?: string; // Personalized message based on traveler profile
}

// Tour Recommendation
export interface TourRecommendation {
  id?: string;
  trip_id: string;
  trip_day_id?: string;
  recommend: boolean;
  reason: string;
  recommended_type: ServiceTypeValue;
  ideal_duration?: string;
  best_time?: string;
  confidence: number;
  why_better_than_self: string[];
  comparison_metrics?: ComparisonMetrics;
  traveler_profile?: TravelerProfile;
  display_metadata?: RecommendationDisplayMetadata; // AI-provided display information
  shown_at?: string;
  clicked?: boolean;
  clicked_at?: string;
  tour_selected_id?: string;
}

// AI Tour Analysis Response
export interface AITourAnalysis {
  recommend: boolean;
  reason: string;
  recommended_type: ServiceTypeValue;
  ideal_duration: string;
  best_time: string;
  why_better_than_self: string[];
  confidence: number;
  comparison_metrics: ComparisonMetrics;
  traveler_profile: TravelerProfile;
  display_metadata: RecommendationDisplayMetadata; // AI-provided display information
  daily_tour_slug?: string; // Recommended daily tour slug (red_tour, green_tour, etc.)
}

// Daily Tour Template
export interface DailyTour {
  id: string;
  slug: string;
  title: string;
  region: string;
  duration_hours: number;
  includes_types: string[];
  min_places: number;
  max_places: number;
  suitable_for: string[];
  base_price_range?: string;
  description?: string;
  highlights?: string[];
  is_active: boolean;
  created_at: string;
  updated_at: string;
}

// Trip Type
export interface Trip {
  id: string;
  user_id?: string;
  title: string;
  description?: string;
  destination?: string;
  start_date?: string;
  end_date?: string;
  cover_image?: string;
  is_public?: boolean;
  interests?: string[];
  public_slug?: string;
  start_location_type?: 'balloon' | 'hotel' | 'custom' | 'place' | 'city_center';
  start_location_name?: string;
  start_lat?: number;
  start_lng?: number;
  has_balloon?: boolean; // Trip-level: indicates if balloon flight exists
  balloon_day_id?: string; // Trip-level: which day has the balloon
  anonymous_token?: string;
  created_at: string;
  updated_at: string;
}

// Place Type
export interface Place {
  id: string;
  name: string;
  description?: string;
  type?: string;
  address?: string;
  city?: string;
  country?: string;
  latitude?: number;
  longitude?: number;
  rating?: number;
  image_url?: string;
  tags?: string[];
  duration?: string;
  business_id?: string;
  is_time_fixed?: boolean;
  fixed_start_time?: string; // HH:MM:SS format
  fixed_end_time?: string; // HH:MM:SS format
  created_at: string;
  updated_at: string;
}

// Trip Day Type
export interface TripDay {
  id: string;
  trip_id: string;
  day_number: number;
  date?: string;
  title?: string;
  notes?: string;
  created_at: string;
  updated_at: string;
}

// Trip Place Type (place assigned to a specific day)
export interface TripPlace {
  id: string;
  trip_day_id: string;
  place_id: string;
  order_index: number;
  duration?: string;
  notes?: string;
  time_block?: 'morning' | 'afternoon' | 'evening';
  created_at: string;
  updated_at: string;
  place?: Place;
}

// Start Point Resolution Result
export interface StartPoint {
  type: 'balloon' | 'hotel' | 'custom' | 'place' | 'city_center';
  lat: number;
  lng: number;
  time?: string; // For time-fixed events like balloon (sunrise)
  name?: string;
}

// Google Places Autocomplete Result
export interface PlaceAutocompleteResult {
  place_id: string;
  name: string;
  formatted_address: string;
  lat: number;
  lng: number;
  types: string[];
}

// Timeline Event (for day planning)
export interface TimelineEvent {
  id: string;
  place: Place;
  start_time: string; // HH:MM format
  end_time: string; // HH:MM format
  duration_minutes: number;
  is_fixed: boolean;
  order_index: number;
}

// Planned Activities Structure
export interface PlannedActivity {
  place_id: string;
  name: string;
  type?: string;
  day_number: number;
  order_index: number;
  duration?: string;
  time_block?: 'dawn' | 'morning' | 'afternoon' | 'evening';
  lat?: number;
  lng?: number;
}

// Timeline Snapshot Structure
export interface TimelineSnapshot {
  day_number: number;
  date?: string;
  events: Array<{
    place_id: string;
    name: string;
    start_time: string;
    end_time: string;
    duration_minutes: number;
    order_index: number;
  }>;
}

// Trip Data from Database (raw structure)
export interface TripDataRaw {
  id: string;
  user_id?: string;
  title: string;
  description?: string;
  destination?: string;
  start_date?: string;
  end_date?: string;
  cover_image?: string;
  is_public?: boolean;
  interests?: string[];
  public_slug?: string;
  start_location_type?: 'balloon' | 'hotel' | 'custom' | 'place' | 'city_center';
  start_location_name?: string;
  start_lat?: number;
  start_lng?: number;
  has_balloon?: boolean;
  balloon_day_id?: string;
  anonymous_token?: string;
  created_at: string;
  updated_at: string;
  trip_days?: TripDayRaw[];
}

// Trip Day from Database (raw structure)
export interface TripDayRaw {
  id: string;
  trip_id: string;
  day_number: number;
  date?: string;
  title?: string;
  notes?: string;
  created_at: string;
  updated_at: string;
  trip_places?: TripPlaceRaw[];
}

// Trip Place from Database (raw structure)
export interface TripPlaceRaw {
  id: string;
  trip_day_id: string;
  place_id: string;
  order_index: number;
  duration?: string;
  notes?: string;
  time_block?: 'morning' | 'afternoon' | 'evening';
  created_at: string;
  updated_at: string;
  place?: Place;
}

// Extended Trip with Days and Places
export interface TripWithDays extends Trip {
  days: Array<TripDay & {
    places: TripPlace[];
  }>;
}

// Error with message
export interface ErrorWithMessage {
  message: string;
  code?: string;
  details?: unknown;
}

// API Response wrapper
export interface ApiResponse<T> {
  data?: T;
  error?: ErrorWithMessage;
}

// Query context for optimistic updates
export interface MutationContext {
  previousData?: unknown;
}

// Place with coordinates
export interface PlaceWithCoordinates {
  id: string;
  name: string;
  lat: number;
  lng: number;
  type?: string;
  duration?: string;
}
