package com.ffii.fpsms.modules.pickOrder.entity

import com.ffii.core.support.AbstractRepository
import org.springframework.data.jpa.repository.Modifying
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.stereotype.Repository

@Repository
interface TruckLaneVersionRepository : AbstractRepository<TruckLaneVersion, Long> {
    fun findAllByTruckLanceCodeAndDeletedFalseOrderByCreatedDesc(truckLanceCode: String): List<TruckLaneVersion>
    fun findAllByDeletedFalseOrderByCreatedDesc(): List<TruckLaneVersion>
    fun findByIdAndDeletedFalse(id: Long): TruckLaneVersion?

    @Modifying(clearAutomatically = true, flushAutomatically = true)
    @Query(
        """
        UPDATE TruckLaneVersion v
        SET v.createdBy = :actor, v.modifiedBy = :actor
        WHERE v.id = :id
        """,
    )
    fun updateActor(@Param("id") id: Long, @Param("actor") actor: String): Int
}

