package com.ffii.fpsms.m18.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 M18CunitRepository : AbstractRepository<M18Cunit, Long> {

    @Modifying
    @Query("DELETE FROM M18Cunit c WHERE c.m18Id = :m18Id")
    fun deleteByM18Id(@Param("m18Id") m18Id: Long): Int

    fun findFirstByM18IdAndUnitIdAndDeletedFalse(m18Id: Long, unitId: Long): M18Cunit?

    fun findFirstByM18IdAndDeletedFalseOrderByIdAsc(m18Id: Long): M18Cunit?

    fun countByDeletedFalse(): Long
}
