import type { LogisticsStepType, TransferHandlerMode } from "../enums.js"

/* ─── Références inline ──────────────────────────────────────────────── */

export interface LogisticsStepStationRef {
    id: string
    name: string
}

export interface LogisticsStepRunnerRef {
    id: string
    displayName: string | null
    username: string
}

/* ─── Step DTOs ──────────────────────────────────────────────────────── */

export interface LogisticsRouteStepDto {
    id: string
    routeId: string
    /** Station de production (PRODUCTION uniquement) */
    stationId: string | null
    station: LogisticsStepStationRef | null
    /** Station de destination (TRANSPORT uniquement — où le runner livre) */
    destinationStationId: string | null
    destinationStation: LogisticsStepStationRef | null
    stepType: LogisticsStepType
    position: number
    label: string | null
    handlerMode: TransferHandlerMode | null
    assignedRunner: LogisticsStepRunnerRef | null
    estimatedMinutes: number | null
}

/* ─── Route DTOs ─────────────────────────────────────────────────────── */

export interface LogisticsRouteListItemDto {
    id: string
    name: string
    description: string | null
    isDefault: boolean
    active: boolean
    stepsCount: number
    /** Résumé textuel : "Caisse → Cuisine → Emballage → Caisse" */
    stepsSummary: string
    createdAt: string
}

export interface LogisticsRouteDetailDto {
    id: string
    shopId: string
    name: string
    description: string | null
    isDefault: boolean
    active: boolean
    revision: number
    steps: LogisticsRouteStepDto[]
    createdAt: string
    updatedAt: string
}

/* ─── Create / Update DTOs ───────────────────────────────────────────── */

export interface CreateLogisticsRouteStepInput {
    /** Station de production (PRODUCTION uniquement) */
    stationId?: string | null
    /** Station de destination (TRANSPORT uniquement) */
    destinationStationId?: string | null
    stepType: LogisticsStepType
    position: number
    label?: string | null
    handlerMode?: TransferHandlerMode | null
    assignedRunnerId?: string | null
    estimatedMinutes?: number | null
}

export interface CreateLogisticsRouteDto {
    name: string
    description?: string | null
    isDefault?: boolean
    steps: CreateLogisticsRouteStepInput[]
}

export interface UpdateLogisticsRouteDto {
    name?: string
    description?: string | null
    isDefault?: boolean
    active?: boolean
    /** Si fourni, remplace intégralement les étapes */
    steps?: CreateLogisticsRouteStepInput[]
}
