package com.ffii.fpsms.modules.master.entity

import com.ffii.core.entity.BaseEntity
import com.ffii.fpsms.modules.master.enums.ShopType
import com.ffii.fpsms.modules.master.enums.ShopTypeConverter
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.PrimaryKeyJoinColumn
import jakarta.persistence.SecondaryTable
import jakarta.persistence.Table
import jakarta.validation.constraints.Size
import jakarta.validation.constraints.NotNull
import jakarta.persistence.Convert
import java.time.LocalTime

@Entity
@Table(name = "shop")
@SecondaryTable(name = "truck", pkJoinColumns = [PrimaryKeyJoinColumn(name = "shopId", referencedColumnName = "id")])
open class ShopAndTruck : BaseEntity<Long>() {

    // --- Shop fields ---
    @Size(max = 300)
    @NotNull
    @Column(name = "name", nullable = false, length = 300)
    open var name: String? = null

    @Size(max = 50)
    @NotNull
    @Column(name = "code", nullable = false, length = 50)
    open var code: String? = null

    @Convert(converter = ShopTypeConverter::class)
    @Column(name = "type", length = 10)
    open var type: ShopType? = null

    
    @Size(max = 50)
    @NotNull
    @Column(name = "contactNo", length = 50)
    open var contactNo: String? = null

    // --- Truck fields (secondary table) ---
    @Column(table = "truck", name = "TruckLanceCode", length = 50)
    open var truckLanceCode: String? = null

    @Column(table = "truck", name = "departureTime")
    open var departureTime: LocalTime? = null

    @Column(table = "truck", name = "LoadingSequence")
    open var loadingSequence: Long? = null

    @Size(max = 255)
    @Column(table = "truck", name = "districtReference", length = 255)
    open var districtReference: String? = null

    @Column(table = "truck", name = "Store_id")
    open var storeId: String? = null

    @Column(table = "truck", name = "remark")
    open var remark: String? = null
}
