package com.example.demo.data;

import com.example.demo.model.Employee;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface Repository5 extends JpaRepository<Employee, Integer> {

    List<Employee> findByLastName(String lastName);

    List<Employee> findByJob_JobId(String jobId);

    List<Employee> findByDepartment_Location_City(String city);

    @Query("SELECT emp FROM Employee emp WHERE emp.salary BETWEEN :min AND :max ORDER BY emp.salary")
    List<Employee> findBySalary(BigDecimal min, BigDecimal max);

    /* default List<String> namesByYear(int year) {
        return List.of("Ala", "Ola", "Ela");
    } */

    @Query(nativeQuery=true,
            value="SELECT first_name || ' ' || last_name"
                    + " FROM employees"
                    + " WHERE extract(year FROM hire_date) = :year"
                    + " ORDER BY last_name")
    List<String> namesByYear(int year);
}
