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

import com.itsol.quantrivanphong.manager.reportdetail.bussiness.ReportProjectBussiness;
import com.itsol.quantrivanphong.manager.reportdetail.dto.request.ReportDTO;
import com.itsol.quantrivanphong.manager.reportdetail.dto.request.TimesheetRequestDTO;
import com.itsol.quantrivanphong.manager.reportdetail.dto.response.ReportResponseDTO;
import com.itsol.quantrivanphong.model.Employee;
import com.itsol.quantrivanphong.model.Project;
import com.itsol.quantrivanphong.model.ProjectReport;
import com.itsol.quantrivanphong.model.TimeSheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(path = "/admin/report")
public class ReportProjectController {
    @Autowired
    private ReportProjectBussiness reportProjectBussiness;

//======================================================================================================================
    //Danh sách các dự án đang trong thời gian triển khai

    @GetMapping(path = "/project/all")
    public ResponseEntity<List<Project>> listProjectWorking(){
        List<Project> projectList = reportProjectBussiness.listProjectWorking();
        return ResponseEntity.ok(projectList);
    }

//======================================================================================================================

    //Hiển thị danh sách timesheet của các thành viên đã viết báo cáo trong ngày hôm đó

    @GetMapping(path = "/project/timesheet",consumes = "application/json", produces = "application/json")
    public ResponseEntity<List<TimeSheet>> findAllTimesheetStatusTrue(@RequestBody ReportDTO reportDTO){
        List<TimeSheet> timeSheetList = reportProjectBussiness.findAllTimesheetStatusTrue(reportDTO);
        return  ResponseEntity.ok(timeSheetList);
    }


    //Nút "kiểm tra" : Lọc các thành viên chưa viết báo cáo và tự khởi tạo timesheet với trạng thái thái = false

    @GetMapping(path = "/project/updateLack", consumes = "application/json", produces = "application/json")
    public ResponseEntity<String> updateTimesheetStatus(@RequestBody ReportDTO reportDTO){
        String mess = reportProjectBussiness.updateTimesheetStatus(reportDTO);
        return ResponseEntity.ok(mess);
    }

    //Quản trị viên duyệt và đánh dấu (đã duyệt, từ chối) mặc định là chưa duyệt (update bảng timesheet theo id)

    @PostMapping(path = "/project/check", consumes = "application/json", produces = "application/json")
    public ResponseEntity<String> updateTimesheetChecked(@RequestBody TimesheetRequestDTO timesheetRequestDTO){
        String mess = reportProjectBussiness.updateTimesheetChecked(timesheetRequestDTO);
        return ResponseEntity.ok(mess);
    }


    //Danh sách thành viên trong Dự án thiếu báo cáo ngày hôm đó
    @GetMapping(path = "/project/alllack",consumes = "application/json", produces = "application/json")
    public ResponseEntity<List<Employee>> listLackOfReport(@RequestBody ReportDTO reportDTO){
        List<Employee> employeeList = reportProjectBussiness.listLackOfReport(reportDTO);
        return  ResponseEntity.ok(employeeList);
    }


    //=================================================================================================================


    //Tạo một báo cáo mới
    @PostMapping(path = "/project/newReport", consumes = "application/json", produces = "application/json")
    public ResponseEntity<String> insertProjectReport(@RequestBody ReportDTO reportDTO ){
        String mess = reportProjectBussiness.insertProjectReport(reportDTO);
        return ResponseEntity.ok(mess);
    }


    //Báo cáo gần nhất của dự án
    @GetMapping(path = "/project/latest",consumes = "application/json", produces = "application/json")
    public ResponseEntity<ProjectReport> latestReport(@RequestBody ReportDTO reportDTO){
            ProjectReport projectReport = reportProjectBussiness.latestReport(reportDTO);
        return  ResponseEntity.ok(projectReport);
    }

    // Tất cả các báo cáo của dự án
    @GetMapping(path = "/project/allReport",consumes = "application/json", produces = "application/json")
    public ResponseEntity<List<ProjectReport>> allProjectReport(@RequestBody ReportDTO reportDTO){
            List<ProjectReport> projectReportList = reportProjectBussiness.allProjectReport(reportDTO);
        return  ResponseEntity.ok(projectReportList);
    }


    //=================================================================================================================


    // Danh sách thành viên không viết timesheet
    @GetMapping(path = "/project/allEmployee",consumes = "application/json", produces = "application/json")
    public ResponseEntity<List<Employee>> listEmployeeLack(@RequestBody ReportDTO reportDTO){
        List<Employee> employeeList = reportProjectBussiness.listEmployeeLack(reportDTO);
        return  ResponseEntity.ok(employeeList);
    }

    // Chi tiết tiếu timesheet của mỗi thành viên
    @GetMapping(path = "/project/allEmployee/id",consumes = "application/json", produces = "application/json")
    public ResponseEntity<ReportResponseDTO> listEmployeeLackDetail(@RequestBody ReportDTO reportDTO){
        ReportResponseDTO reportResponseDTO = new ReportResponseDTO();
        reportResponseDTO.setTimeSheetList(reportProjectBussiness.listDateOfLack(reportDTO));
        reportResponseDTO.setNumberOflack(reportProjectBussiness.numberLack(reportDTO));
        return  ResponseEntity.ok(reportResponseDTO);
    }




    //=================================================================================================================



}
