package com.ffii.fpsms.modules.deliveryOrder.entity

import com.ffii.core.support.AbstractRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository
import java.io.Serializable

@Repository
interface DeliveryOrderLineRepository : AbstractRepository<DeliveryOrderLine, Long> {
    fun findByM18DataLogIdAndDeletedIsFalse(m18datalogId: Serializable): DeliveryOrderLine?

    @Query(
        "SELECT dol FROM DeliveryOrderLine dol " +
            "WHERE dol.deleted = false " +
            "AND dol.deliveryOrder.id = :deliveryOrderId " +
            "AND dol.m18DataLog.refType = :refType"
    )
    fun findAllByDeliveryOrderIdAndM18RefTypeAndDeletedIsFalse(
        deliveryOrderId: Long,
        refType: String
    ): List<DeliveryOrderLine>

    @Query(
        "SELECT dol FROM DeliveryOrderLine dol " +
            "WHERE dol.deleted = false AND dol.item IS NOT NULL AND dol.item.isFee = true"
    )
    fun findAllByDeletedIsFalseAndItemIsFeeTrue(): List<DeliveryOrderLine>
}