package gaf3.core.services.role.dao

import gaf3.core.services.role.entity.GafRoleItem
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query

interface GafRoleItemDAO : JpaRepository<GafRoleItem, String> {

    @Query(value = "select p from GafRoleItem p where p.type is null or p.type = '' order by p.ranking")
    fun listTypes(): List<GafRoleItem>

    @Query(value = "select p from GafRoleItem p where p.type is not null and p.type <> '' and (?1 is null or p.type = ?1) order by p.ranking")
    fun listItems(type: String?): List<GafRoleItem>

    fun existsByName(name: String): Boolean

    fun existsByCode(code: String): Boolean

    fun findOneByName(name: String): GafRoleItem?
}
