import { Passenger } from '@edr/types';

// Enhanced Booking Types 
export interface Booking {
  id: string;
  bookingRef: string;
  passengerId: string;
  passenger?: Passenger.IPassenger;
  scheduleId: string;
  status: 'DRAFT' | 'PENDING_PAYMENT' | 'CONFIRMED' | 'CANCELLED' | 'COMPLETED' | 'NO_SHOW' | 'REFUNDED';
  currency: string;
  totalMinor: number;
  adultCount: number;
  childCount: number;
  displayCurrency?: string;
  displayTotalMinor?: number;
  bookingType: string;
  contactEmail?: string;
  contactPhone?: string;
  source: string;
  promoCode?: string;
  paidAt?: string;
  createdAt: string;
  updatedAt: string;
}

// Station Types
export interface Station {
  id: string;
  code: string;
  name: string;
  city: string;
  countryCode?: string;
  isOperational: boolean;
  timezone: string;
  lat: number;
  lng: number;
  createdAt: string;
}

// Train Types
export interface Train {
  id: string;
  number: string;
  name: string;
  operatorId: string;
  operatorName?: string;
  description?: string;
  isActive: boolean;
  createdAt: string;
  updatedAt: string;
}

// Coach Types
export interface Coach {
  id: string;
  coachNumber: string;
  label: string;
  seatClassId: string;
  coachType?: string;
  mode: string;
  seatArrangement?: string;
  bedArrangement?: string;
  amenities?: any;
  totalUnits: number;
  isActive: boolean;
  createdAt: string;
  updatedAt: string;
}

// Schedule Types
export interface TrainSchedule {
  id: string;
  trainId: string;
  routeId?: string;
  originStationId: string;
  destinationStationId: string;
  departureAt: string;
  arrivalAt: string;
  durationMinutes: number;
  status: 'SCHEDULED' | 'BOARDING' | 'EN_ROUTE' | 'ARRIVED' | 'CANCELLED' | 'DELAYED';
  stopsCount: number;
  reservedCount: number;
  onTimePercent: number;
  carbonRating: string;
  notes?: string;
  train?: Train;
  originStation?: Station;
  destinationStation?: Station;
}

// Route Types
export interface Route {
  id: string;
  code: string;
  name: string;
  description?: string;
  effectiveFrom: string;
  effectiveUntil?: string;
  active: boolean;
  createdAt: string;
  stops?: RouteStop[];
  fareRules?: RouteFareRule[];
}

export interface RouteStop {
  id: string;
  routeId: string;
  stationId: string;
  sequence: number;
  distanceKm?: number;
  createdAt: string;
}

export interface RouteFareRule {
  id: string;
  routeId: string;
  seatClassId: string;
  passengerCategory: 'ADULT' | 'CHILD';
  baseFareMinor: number;
  discountPercent?: number;
  taxPercent?: number;
  surchargeMinor?: number;
  currency: string;
  validFrom: string;
  validUntil?: string;
  createdAt: string;
}

// Seat Types
export interface Seat {
  id: string;
  coachId: string;
  row: number;
  col: string;
  label: string;
  seatNumber?: string;
  kind: 'STANDARD' | 'PREMIUM' | 'ACCESSIBLE';
  status: 'AVAILABLE' | 'HELD' | 'BOOKED' | 'BLOCKED';
  heldUntil?: string;
  isWindow: boolean;
  isAisle: boolean;
  bedPosition?: string;
  premiumFeeMinor: number;
  eligibility?: string;
}

export interface SeatClass {
  id: string;
  name: string;
  description?: string;
  basePrice: number;
  isActive: boolean;
  createdAt: string;
  updatedAt: string;
}

// Payment Types
export interface PaymentIntent {
  id: string;
  bookingId: string;
  amountMinor: number;
  currency: string;
  method: 'TELEBIRR' | 'CBE_BIRR' | 'EBIRR' | 'CARD' | 'WALLET' | 'WAAFI';
  provider?: string;
  status: 'REQUIRES_ACTION' | 'PROCESSING' | 'SUCCEEDED' | 'FAILED' | 'CANCELLED' | 'REFUNDED';
  providerRef?: string;
  merchantOrderId?: string;
  providerOrderId?: string;
  providerTxnId?: string;
  paidAt?: string;
  refundedAt?: string;
  failureCode?: string;
  failureMessage?: string;
  expiresAt?: string;
  createdAt: string;
  updatedAt: string;
}

// Agent Types
export interface Agent {
  id: string;
  userId: string;
  agentCode: string;
  stationId?: string;
  commissionRate: number;
  active: boolean;
  createdAt: string;
  user?: any;
}

export interface AgentShift {
  id: string;
  agentId: string;
  openedAt: string;
  closedAt?: string;
  openingBalance: number;
  closingBalance?: number;
  reconciled: boolean;
  notes?: string;
}

// Loyalty Types
export interface LoyaltyAccount {
  id: string;
  passengerId: string;
  pointsBalance: number;
  lifetimePoints: number;
  tier: 'BRONZE' | 'SILVER' | 'GOLD' | 'PLATINUM';
  tierUpdatedAt?: string;
  updatedAt: string;
}

export interface LoyaltyReward {
  id: string;
  accountId: string;
  title: string;
  costPoints: number;
  available: boolean;
  description?: string;
}

// Wallet Types
export interface WalletAccount {
  id: string;
  passengerId: string;
  balanceMinor: number;
  status: string;
  holdMinor: number;
  currency: string;
  updatedAt: string;
}

// Notification Types
export interface NotificationTemplate {
  id: string;
  code: string;
  channel: string;
  subject?: string;
  bodyTemplate: string;
  active: boolean;
  createdAt: string;
}

// Promotion Types
export interface Promotion {
  id: string;
  title: string;
  subtitle?: string;
  code: string;
  percentOff?: number;
  amountOffMinor?: number;
  validUntil: string;
  ctaLabel?: string;
  deepLink?: string;
  active: boolean;
  createdAt: string;
}

// Support Types
export interface SupportConversation {
  id: string;
  userId: string;
  assignedAgentId?: string;
  status: 'OPEN' | 'RESOLVED' | 'CLOSED';
  createdAt: string;
  messages?: SupportMessage[];
}

export interface SupportMessage {
  id: string;
  conversationId: string;
  sender: 'USER' | 'BOT' | 'AGENT';
  text: string;
  attachments?: any;
  createdAt: string;
}

// Fraud Types
export interface FraudAlert {
  id: string;
  userId: string;
  eventType: string;
  triggeredRules: string[];
  context: any;
  severity: string;
  acknowledged: boolean;
  createdAt: string;
}

export interface FraudRule {
  id: string;
  type: string;
  enabled: boolean;
  threshold: number;
  config?: any;
  createdAt: string;
  updatedAt: string;
}

// Audit Types
export interface AuditLog {
  id: string;
  userId?: string;
  action: string;
  entityType: string;
  entityId?: string;
  oldData?: any;
  newData?: any;
  ipAddress?: string;
  userAgent?: string;
  createdAt: string;
}

// Dashboard Types
export interface DashboardStats {
  totalBookings: number;
  totalRevenue: number;
  totalPassengers: number;
  activeTrips: number;
  bookingsToday: number;
  revenueToday: number;
  occupancyRate: number;
  averageTicketPrice: number;
  cancellationRate: number;
  onTimePerformance: number;
}

export interface RevenueData {
  date: string;
  revenue: number;
  bookings: number;
}

// Filter Types
export interface BookingFilters {
  status?: string;
  dateFrom?: string;
  dateTo?: string;
  search?: string;
  source?: string;
  paymentStatus?: string;
  page?: number;
  pageSize?: number;
}

export interface PassengerFilters {
  search?: string;
  verified?: boolean;
  nationality?: string;
  registrationDateFrom?: string;
  registrationDateTo?: string;
  page?: number;
  pageSize?: number;
}

export interface PaymentFilters {
  status?: string;
  method?: string;
  dateFrom?: string;
  dateTo?: string;
  amountFrom?: number;
  amountTo?: number;
  page?: number;
  pageSize?: number;
}

// Live Tracking Types
export interface TripLiveStatus {
  id: string;
  scheduleId: string;
  state: string;
  currentLocationLabel?: string;
  progressPercent: number;
  delayMinutes: number;
  currentSpeedKph?: number;
  platformLabel?: string;
  updatedAt: string;
}

export interface StationCrowdSignal {
  id: string;
  stationId: string;
  level: string;
  label: string;
  statusLabel: string;
  confidence?: number;
  observedAt?: string;
  updatedAt: string;
}

// Food & Dining Types
export interface MenuCategory {
  id: string;
  name: string;
}

export interface MenuItem {
  id: string;
  scheduleId: string;
  categoryId: string;
  name: string;
  priceMinor: number;
  currency: string;
  available: boolean;
  availableUntil?: string;
}

export interface FoodOrder {
  id: string;
  bookingId: string;
  status: 'PENDING' | 'PREPARING' | 'READY' | 'DELIVERED' | 'CANCELLED';
  totalMinor: number;
  currency: string;
  specialInstructions?: string;
  estimatedReadyAt?: string;
  createdAt: string;
}

// Verifayda Types
export interface VerifaydaVerification {
  id: string;
  bookingId?: string;
  nationalId: string;
  requestPayload: any;
  responsePayload?: any;
  verified: boolean;
  failureReason?: string;
  verifiedAt?: string;
  createdAt: string;
}

// Admin User Types
export interface AdminUser {
  id: string;
  email: string;
  fullName: string;
  role: 'ADMIN' | 'AGENT' | 'SUPERVISOR' | 'STAFF';
  active: boolean;
  lastLoginAt?: string;
  createdAt: string;
}
