package de.votian.services.repository;

import de.votian.services.entity.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
import java.util.Optional;

public interface EmployeeRepository extends JpaRepository<Employee, Long> {

    Optional<Employee> findByUserId(Long userId);

    List<Employee> findByHeadquartersIdOrderByIdAsc(Long headquartersId);

    @Query("SELECT emp FROM Employee emp JOIN User usr ON emp.userId = usr.id " +
           "WHERE emp.userId = :userId AND usr.account = :account AND usr.headquartersId = :hqId")
    Optional<Employee> findByUserIdAndAccountAndHq(
            @Param("userId") Long userId, @Param("account") String account, @Param("hqId") Long hqId);
}
