export interface YardOption {
  id: string;
  name: string;
  code: string;
  country?: string;
}

export interface EligibleContainerBooking {
  id: string;
  reference: string;
  customer: string;
  containerType: string;
  quantity: number;
  weightTons: number;
  origin: string;
  destination: string;
  preferredDepartureDate: string;
  status: string;
}

export interface EligibleContainerBookingsResponse {
  count: number;
  items: EligibleContainerBooking[];
}

export interface WagonPlanAllocation {
  bookingId: string;
  bookingReference: string;
  allocatedWeightTons: number;
}

export interface WagonPlanRow {
  sequenceNo: number;
  capacityTons: number;
  lengthMeters: number;
  assignedWeightTons: number;
  allocations: WagonPlanAllocation[];
}

export interface TrainSchedulePreviewResponse {
  valid: boolean;
  violations: string[];
  summary: {
    totalBookings: number;
    totalWeightTons: number;
    wagonType: string;
    wagonsNeeded: number;
    totalLengthMeters: number;
  };
  bookingIds: string[];
  wagonPlan: WagonPlanRow[];
}

export interface LocomotiveRecord {
  id: string;
  code: string;
  name?: string | null;
  maxPullWeightTons: number;
  maxTrainLengthMeters: number;
  status: 'AVAILABLE' | 'ASSIGNED' | 'MAINTENANCE' | 'OUT_OF_SERVICE';
  locomotiveType?: 'DIESEL' | 'ELECTRIC';
}

export interface TrainScheduleListItem {
  id: string;
  scheduleDate: string;
  routeName?: string | null;
  origin: string | null;
  destination: string | null;
  locomotive:
    | {
        id: string;
        code: string;
        name?: string | null;
      }
    | null;
  wagonCount: number;
  totalWeightTons: number;
  totalLengthMeters: number;
  bookingsCount: number;
  status: string;
}

export interface TrainScheduleDetail {
  id: string;
  status: string;
  route?: {
    id: string;
    name: string;
  } | null;
  scheduledDepartureDate: string;
  scheduledArrivalDate?: string | null;
  originStation?: {
    id: string;
    label?: string;
    code?: string;
  } | null;
  destinationStation?: {
    id: string;
    label?: string;
    code?: string;
  } | null;
  trainSet?: {
    id: string;
    status: string;
    wagonCount: number;
    totalWeightTons: number;
    totalLengthMeters: number;
      locomotive?: {
        id: string;
        code: string;
        name?: string | null;
        status: string;
        maxPullWeightTons: number;
        maxTrainLengthMeters?: number;
      } | null;
    wagons: Array<{
      id: string;
      sequenceNo: number;
      capacityTons: number;
      lengthMeters: number;
      assignedWeightTons: number;
      wagonType?: {
        id: string;
        code: string;
        name: string;
      } | null;
      allocations: Array<{
        id: string;
        bookingId: string;
        bookingReference: string | null;
        allocatedWeightTons: number;
      }>;
    }>;
  } | null;
  bookings: Array<{
    id: string;
    reference: string | null;
    customer: string | null;
    weightTons: number;
    status: string | null;
  }>;
}

export interface TrainScheduleFilters {
  originStationId?: string;
  destinationStationId?: string;
  scheduleDate?: string;
}

export interface TrainSchedulePreviewPayload {
  bookingIds: string[];
  scheduleDate: string;
  originStationId: string;
  destinationStationId: string;
}

export interface CreateTrainSchedulePayload {
  routeId: string;
  scheduleDate: string;
  locomotiveId: string;
}
