package org.raddatz.familienarchiv.person;

import org.raddatz.familienarchiv.person.PersonNameAlias;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.UUID;

public interface PersonNameAliasRepository extends JpaRepository<PersonNameAlias, UUID> {

    List<PersonNameAlias> findByPersonIdOrderBySortOrderAscCreatedAtAsc(UUID personId);

    @Query("SELECT COALESCE(MAX(a.sortOrder), -1) FROM PersonNameAlias a WHERE a.person.id = :personId")
    int findMaxSortOrder(UUID personId);
}
