package com.itsol.quantrivanphong.repository;

import com.itsol.quantrivanphong.model.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface EmployeeRepository  extends JpaRepository<Employee,Integer > {
    public Employee findEmployeeByUsername(String username);

    public Employee findEmployeeByEmailAddress(String emailAddress);

    public Employee findEmployeeByUsernameAndPassword(String username, String password);

    Employee findByEmailAddress(String emailAddress);


    //==================================================================================================================
    //Emplyee Repository Of Hieunv

    @Query(value = "SELECT e.username FROM employee e JOIN eproject ep ON e.id = ep.employee_id JOIN project p  ON ep.project_id = p.id WHERE p.id = ?1 AND ep.position = 'team_lead' GROUP BY e.id",nativeQuery = true)
    String findTeamLeader(int projectId);

    @Query(value = "SELECT COUNT(e.id)FROM employee e JOIN eproject ep ON e.id = ep.employee_id JOIN project p  ON ep.project_id = p.id WHERE p.id = ?1 AND ep.position = 'member'", nativeQuery = true)
    int numberOfMember(int projectId);
}
