package com.zioinfo.hrm.dashboard;

import com.zioinfo.hrm.common.ApiResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/hrm/dashboard")
@RequiredArgsConstructor
public class DashboardController {

    private final DashboardMapper dashboardMapper;

    @GetMapping
    public ApiResponse<Map<String, Object>> dashboard(
            @RequestParam(defaultValue = "6") int months) {
        Map<String, Object> data = new HashMap<>();
        data.put("kpi", dashboardMapper.getKpiSummary());
        data.put("headcountTrend", dashboardMapper.getHeadcountTrend(months));
        data.put("deptHeadcount", dashboardMapper.getDeptHeadcount());
        data.put("attendance", dashboardMapper.getAttendanceToday());
        int year = LocalDate.now().getYear();
        int month = LocalDate.now().getMonthValue();
        data.put("payrollSummary", dashboardMapper.getPayrollSummary(year, month));
        data.put("recruitmentPipeline", dashboardMapper.getRecruitmentPipeline());
        data.put("pendingApprovals", dashboardMapper.getPendingApprovals());
        return ApiResponse.ok(data);
    }
}
