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

import com.ffii.fpsms.modules.pickOrder.entity.Truck
import java.time.LocalTime

/**
 * MessageResponse.entity for truck mutations.
 * Do not return [Truck] JPA entities directly — lazy `logistic` / `shop` proxies break Jackson serialization.
 */
data class TruckMessageEntity(
    val id: Long?,
    val truckLanceCode: String?,
    val departureTime: LocalTime?,
    val shopName: String?,
    val shopCode: String?,
    val loadingSequence: Int?,
    val storeId: String?,
    val districtReference: String?,
    val remark: String?,
    val shopId: Long? = null,
    val logisticId: Long? = null,
)

fun Truck.toMessageEntity(): TruckMessageEntity =
    TruckMessageEntity(
        id = id,
        truckLanceCode = truckLanceCode,
        departureTime = departureTime,
        shopName = shopName,
        shopCode = shopCode,
        loadingSequence = loadingSequence,
        storeId = storeId,
        districtReference = districtReference,
        remark = remark,
        shopId = shop?.id,
        logisticId = logistic?.id,
    )
