import { ReactNode } from 'react';

// ============================================
// TIPOS DE AUTENTICAÇÃO
// ============================================

export interface User {
  email: string;
  nome: string;
  apelido: string;
  contacto: string;
  morada: string;
  nif: string;
  id_user?: string;
  [key: string]: any;
}

export interface AuthContextType {
  user: User | null;
  token: string | null;
  isAuthenticated: boolean;
  isLoading: boolean;
  login: (email: string, password: string) => Promise<void>;
  logout: () => Promise<void>;
  updateProfile: (nome?: string, apelido?: string, oldPassword?: string, newPassword?: string) => Promise<void>;
  error: string | null;
}

export interface LoginResponse {
  status: number;
  message?: string;
  token?: string;
  user?: User;
  [key: string]: any;
}

export interface ApiMessageResponse {
  status: number;
  message?: string;
}

export interface UserData {
  email: string;
  nome: string;
  apelido: string;
  contacto: string;
  morada: string;
  nif: string;
}

export interface AuthProviderProps {
  children: ReactNode;
}

// ============================================
// TIPOS DE RESERVAS
// ============================================

export interface Reserva {
  destino: string;
  referenciaAgencia: string;
  referenciaViagem: string;
  startDate: string;
  status: string;
  statusCode: string;
  imagemCidade: string;
  pais: string;
}

export interface ReservasResponse {
  status: string | number;
  user?: User;
  message?: string;
  reservas: Reserva[];
}

export interface HotelFoto {
  src: string;
  srcZoom: string;
  alt: string;
}

export interface Passageiro {
  nome: string;
  sobrenome: string;
  genero: string;
  dataNascimento: string;
  nacionalidade: string;
  morada: string;
  paisEmissao: string;
  numeroDocumento: string;
  dataDeEmissao: string;
  dataDeValidade: string;
  telemovel: string;
  email: string;
}

export interface HotelInfo {
  name: string;
  data: string;
  noites: number;
  regime: string;
  quarto: string;
  id_hotel: string;
  imagemexterna: string;
  imageminterna: string;
  stars: string;
}

export interface Escala {
  companyCode: string;
  company: string;
  number: string;
  departureAirportCode: string;
  mapaAirportDeparture?: string;
  departureAirport: string;
  departureDateTime: string;
  departureDate: string;
  departureTime: string;
  arrivalAirportCode: string;
  mapaAirportArrival?: string;
  arrivalAirport: string;
  arrivalDateTime: string;
  arrivalDate: string;
  arrivalTime: string;
  flightTime: string;
  mala: boolean;
  malaLabel: string;
  class: string;
  infoAeroportoDeparture?: InfoAeroporto;
  infoAeroportoArrival?: InfoAeroporto;
  
}

export interface VooSegment {
  departureDate: string;
  departureTime: string;
  arrivalDate: string;
  arrivalTime: string;
  number: string;
  class: string;
  malaLabel: string;
  departureAirportCode: string;
  arrivalAirportCode: string;
  departureAirport: string;
  arrivalAirport: string;
  departureAirportTimeZone: string;
  arrivalAirportTimeZone: string;
  flightTime: string;
}

export interface VooLeg {
  departureDate: string;
  infoEscalas: Escala[];
  infoAeroportoDeparture?: InfoAeroporto;
  infoAeroportoArrival?: InfoAeroporto;
}

export interface InfoAeroporto {
  name: string;
  timezone: string;
  iso_country?: string;
  gps: {
    lng: number | string;
    lat: number | string;
  };
}

export interface Extra {
  name: string;
  price: number;
}

export type VooDirection = VooLeg | VooSegment[];

export interface JsonData {
  hotel: HotelInfo[];
  voo: {
    departure: VooDirection;
    arrival: VooDirection;
  };
  extra?: Extra[];
  extras?: Extra[];
}

export interface Cidade {
  id_cidade: string;
  cod_pais: string;
  imagem: string;
  imagem_banner: string;
  thumbnail: string;
  destaque: string;
  destaque_top: string;
  outros_destinos: string;
  lat: string;
  lng: string;
  zoom: string;
  ordem: string;
  reference: string;
  ordemFooter: string;
  html_image_social: string;
  activofooter: string;
  activo: string;
  cod_tag: string;
  categoria: string;
  lowAeroporto: string;
  lowData: string;
  lowNoites: string;
  lowRegimeKey: string;
  lowPreco: string;
  imagemMenu: string;
}

export interface ReservaData {
  id_reserva: string;
  destino: string;
  startDate: string;
  endDate: string;
  referenciaViagem: string;
  referenciaAgencia: string;
  localizador: string;
  noites: string;
  status: string;
  pessoas: string;
  adultos: string;
  criancas: string;
  quartos: string;
  jsonData: string | JsonData;
  precoTotalFinal: string;
  valorPago: string;
  valorAPagar: string;
  operador: string;
  linkTransfers?: string;
  cidade: Cidade | null;
  imagemCidade?: string;
  infoCidade: string;
  passageiros: Passageiro[];
  quartosPassageiros?: QuartoPassageiro[];
}

export interface QuartoPassageiro {
  cod_user_api: string;
  idade: string;
}

export interface ReservaResponse {
  status: number;
  message?: string;
  reserva?: ReservaData;
  pagamentos?: Pagamento[];
  documentos?: Documento[];
}

export interface Pagamento {
  valor: string;
  estado: string;
  metodoPagamento: string;
  data_hora: string;
  data_pagamento: string;
}

export interface Documento {
  nome: string;
  idDocumento: string;
  caminhoFicheiro: string;
  checksum: string | null;
}

// ============================================
// TIPOS DE PERFIL
// ============================================

export interface UserInfo {
  nome: string;
  apelido: string;
  email: string;
}

export interface UserInfoResponse {
  status: number;
  message?: string;
  user?: UserInfo;
}

// ============================================
// TIPOS DE CONTACTOS
// ============================================

export interface ContactData {
  email: string;
  telephone: string;
  mobilePhone: string;
  address: string;
  horarios: string;
  whatsapp: string | null;
  emergencyPhone: string | null;
  coordenadas?: string | null;
}

export interface SocialMedia {
  key: string;
  title: string;
  value: string;
}

export interface ContactResponse {
  status: number;
  message?: string;
  contact?: ContactData;
  socials?: SocialMedia[];
}

// ============================================
// TIPOS DE COMPONENTES
// ============================================

export interface CardDestinoProps {
  destino: string;
  referenciaAgencia: string;
  referenciaViagem: string;
  startDate: string;
  status: string;
  statusCode: string;
  imagemCidade: string;
  imageUrl: string;
  color: string;
  textColor: string;
}

// ============================================
// TIPOS DE DOCUMENTOS CHECKSUMS
// ============================================

export interface DocumentoChecksum {
  idDocumento: string;
  checksum: string;
  nome: string;
  caminhoFicheiro: string;
}

export interface ReservaDocumentos {
  referenciaViagem: string;
  documentos: DocumentoChecksum[];
}

export interface DocumentosChecksumsResponse {
  status: number;
  message?: string;
  documentos: ReservaDocumentos[];
}
