package com.itsol.quantrivanphong.manage.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> findAllLeaveForm();

    LeaveForm findLeaveFormByEmployeeAndId(Employee employee, int id);

    LeaveForm findLeaveFormById(int i);

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

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

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