package com.itsol.quantrivanphong.manager.reportdetail.repository;

import com.itsol.quantrivanphong.model.ProjectReport;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


public interface ProjectReportRepository extends JpaRepository<ProjectReport, Integer> {

    @Query(value = "SELECT * FROM project_report pr WHERE pr.project_id = ?1 ORDER BY pr.created_at DESC limit 1", nativeQuery = true)
    ProjectReport latestReport(int projectId);


    @Query(value = "SELECT * FROM project_report pr WHERE pr.project_id = ?1 ORDER BY pr.created_at DESC", nativeQuery = true)
    List<ProjectReport> allProjectReport(int projectId);

    @Transactional
    @Modifying
    @Query(value = "INSERT INTO project_report(project_name, team_leader, number_of_members, calendar_effort, lack_of_reports, created_at, updated_at, status, project_id, first_date, final_date) VALUES (?1, ?2, ?3, ?4, ?5, CURRENT_DATE(), CURRENT_DATE() ,?6, ?7, ?8, ?9)",nativeQuery = true)
    void insertProjectReport(String projectName, String teamLeader, int NumberOfMember, int CalendarEffort, int LackOfReport, boolean status, int projectId, String firstDate, String finalDate);
}
