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

import com.ffii.core.support.AbstractRepository
import com.ffii.fpsms.modules.master.entity.projections.SearchId
import com.ffii.fpsms.modules.master.enums.ShopType
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
interface ShopRepository : AbstractRepository<Shop, Long> {
    fun findAllByDeletedIsFalse(): List<Shop>

    fun findByIdAndDeletedIsFalse(id: Long): Shop?

    fun findByM18IdAndTypeAndDeletedIsFalse(m18Id: Long, type: ShopType): Shop?

    @Query(
        nativeQuery = true,
        value = "select s.m18Id from shop s where s.code regexp ?1 and s.type = ?2 and s.deleted = false")
    fun findM18IdsByCodeRegexpAndTypeAndDeletedIsFalse(codeRegexp: String, type: String): List<Long>?

    @Query(
        nativeQuery = true,
        value = "select s.m18Id from Shop s where s.code not regexp ?1 and s.type = ?2 and s.deleted = false")
    fun findM18IdsByCodeNotRegexpAndTypeAndDeletedIsFalse(codeNotRegexp: String, type: String): List<Long>?
}