package com.ffii.fpsms.modules.pickOrder.web.models

import jakarta.validation.constraints.Size

data class CreateTruckLaneSnapshotRequest(
    @field:Size(max = 100)
    val truckLanceCode: String? = null,
    @field:Size(max = 500)
    val note: String? = null,
    /** When set (e.g. scheduled apply without JWT), attributes snapshot to the scheduler. */
    @field:Size(max = 30)
    val createdBy: String? = null,
)

data class RestoreTruckLaneSnapshotRequest(
    val versionId: Long,
)

data class TruckLaneVersionResponse(
    val id: Long,
    val truckLanceCode: String,
    val note: String?,
    val created: String?,
    val createdBy: String? = null,
    /** BaseEntity `modifiedBy`：最後寫入此快照的使用者（通常為 JWT name / staffNo） */
    val modifiedBy: String?,
)

data class TruckLaneVersionLineResponse(
    val truckRowId: Long,
    val truckLanceCode: String?,
    val shopCode: String?,
    val branchName: String?,
    val districtReference: String?,
    val loadingSequence: Int?,
    val departureTime: String?,
    val storeId: String,
    val remark: String?,
    val logisticId: Long?,
)

data class DiffFieldChange(
    val field: String,
    val from: String?,
    val to: String?,
)

data class TruckLaneVersionDiffLine(
    val truckRowId: Long,
    val shopCode: String?,
    val changes: List<DiffFieldChange>,
    /** 快照中的車線代碼（優先 to 版，刪除列時 fallback from）— 供僅欄位異動時顯示車線 */
    val truckLanceCode: String? = null,
    val remark: String? = null,
)

/** 物流主檔異動（版本區間內新增/修改；不依賴 truck 列是否已指派） */
data class LogisticMasterDiffLine(
    val logisticId: Long,
    val type: String,
    val logisticName: String,
    val carPlate: String,
    val changeText: String,
)

data class TruckLaneVersionDiffResponse(
    val fromVersionId: Long,
    val toVersionId: Long,
    val changed: List<TruckLaneVersionDiffLine>,
    val logisticMasterChanges: List<LogisticMasterDiffLine> = emptyList(),
)

