package com.itsol.quantrivanphong.report.leaveform.repository;

import com.itsol.quantrivanphong.model.Employee;
import com.itsol.quantrivanphong.model.LeaveForm;
import com.itsol.quantrivanphong.model.LeaveType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface LeaveFormRepository extends JpaRepository<LeaveForm, Integer> {
//    @Query("select lf from LeaveForm lf")
//    List<LeaveForm> findAll();

    LeaveForm findLeaveFormByEmployeeAndId(Employee employee, int id);

//    LeaveForm findLeaveFormById(int i);

    LeaveForm findLeaveFormByEmployeeAndLeaveTypeAndId(Employee employee, LeaveType leaveType, int id);

    @Modifying
    @Query("update LeaveForm lf set lf.title = ?1, lf.content = ?2 where lf.id = ?3")
    int updateLeaveForm(String title, String content, int id);

    @Modifying
    @Query("update LeaveForm lf set lf.status = true where lf.id = ?1")
    int updateLeaveFormStatus(int id);

    @Query("select lf from LeaveForm lf where lf.employee = ?1")
    List<LeaveForm> showLeaveFormById(Employee employee);
}
