package com.erp.controller;

import com.erp.dto.ApiResponse;
import com.erp.service.SalesReportService;
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/sales-report")
@RequiredArgsConstructor
@Slf4j
public class SalesReportController {

    private final SalesReportService salesReportService;

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

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

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