package com.erp.controller;

import com.erp.dto.ApiResponse;
import com.erp.service.AnalyticsReportService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/report")
@RequiredArgsConstructor
@Slf4j
public class AnalyticsReportController {

    private final AnalyticsReportService analyticsReportService;

    @GetMapping("/production/data")
    public ResponseEntity<ApiResponse<Map<String, Object>>> getProductionReportData(
            @RequestAttribute("company_code") String companyCode,
            @RequestParam Map<String, Object> params) {
        params.put("company_code", companyCode);
        return ResponseEntity.ok(ApiResponse.success(analyticsReportService.getProductionReportData(params)));
    }

    @GetMapping("/inventory/data")
    public ResponseEntity<ApiResponse<Map<String, Object>>> getInventoryReportData(
            @RequestAttribute("company_code") String companyCode,
            @RequestParam Map<String, Object> params) {
        params.put("company_code", companyCode);
        return ResponseEntity.ok(ApiResponse.success(analyticsReportService.getInventoryReportData(params)));
    }

    @GetMapping("/purchase/data")
    public ResponseEntity<ApiResponse<Map<String, Object>>> getPurchaseReportData(
            @RequestAttribute("company_code") String companyCode,
            @RequestParam Map<String, Object> params) {
        params.put("company_code", companyCode);
        return ResponseEntity.ok(ApiResponse.success(analyticsReportService.getPurchaseReportData(params)));
    }

    @GetMapping("/quality/data")
    public ResponseEntity<ApiResponse<Map<String, Object>>> getQualityReportData(
            @RequestAttribute("company_code") String companyCode,
            @RequestParam Map<String, Object> params) {
        params.put("company_code", companyCode);
        return ResponseEntity.ok(ApiResponse.success(analyticsReportService.getQualityReportData(params)));
    }

    @GetMapping("/equipment/data")
    public ResponseEntity<ApiResponse<Map<String, Object>>> getEquipmentReportData(
            @RequestAttribute("company_code") String companyCode,
            @RequestParam Map<String, Object> params) {
        params.put("company_code", companyCode);
        return ResponseEntity.ok(ApiResponse.success(analyticsReportService.getEquipmentReportData(params)));
    }

    @GetMapping("/mold/data")
    public ResponseEntity<ApiResponse<Map<String, Object>>> getMoldReportData(
            @RequestAttribute("company_code") String companyCode,
            @RequestParam Map<String, Object> params) {
        params.put("company_code", companyCode);
        return ResponseEntity.ok(ApiResponse.success(analyticsReportService.getMoldReportData(params)));
    }
}
