package com.pressing.modules.dashboard;

import java.time.LocalDate;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

    private final DashboardService dashboardService;

    public DashboardController(DashboardService dashboardService) {
        this.dashboardService = dashboardService;
    }

    @GetMapping("/kpis")
    public DashboardService.KpiResponse kpis() {
        return dashboardService.kpis();
    }

    // 1. DÉPÔTS EN DÉTAILS
    @GetMapping("/deposits-details")
    public Object getDepositsDetails(
            @RequestParam(required = false) String q,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.getDepositsDetails(q, from, to, page, size);
    }

    // 2. ARTICLES RETIRÉS EN DÉTAILS
    @GetMapping("/pickups-details")
    public Object getPickupsDetails(
            @RequestParam(required = false) String q,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.getPickupsDetails(q, from, to, page, size);
    }

    // 3. RETRAITS EN ATTENTE EN DÉTAILS
    @GetMapping("/pending-pickups-details")
    public Object getPendingPickupsDetails(
            @RequestParam(required = false) String q,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.getPendingPickupsDetails(q, page, size);
    }

    // 4. RETARDS DE TRAITEMENT EN DÉTAILS
    @GetMapping("/late-treatments-details")
    public Object getLateTreatmentsDetails(
            @RequestParam(required = false) String q,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.getLateTreatmentsDetails(q, page, size);
    }

    // 5. RECETTE DU JOUR EN DÉTAILS (PAIEMENTS)
    @GetMapping("/revenue-details")
    public Object getRevenueDetails(
            @RequestParam(required = false) String q,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.getRevenueDetails(q, from, to, page, size);
    }

    // AGENDA DES RENDEZ-VOUS
    @GetMapping("/agenda")
    public Object agenda(
            @RequestParam(required = false) String q,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.agenda(q, from, to, page, size);
    }

    // JOURNAL DES OPÉRATIONS (AUDIT)
    @GetMapping("/audit-logs")
    public Object audits(
            @RequestParam(required = false) String q,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate from,
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate to,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.audits(q, from, to, page, size);
    }
}


/*package com.pressing.modules.dashboard;

import java.time.LocalDate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

    private final DashboardService dashboardService;

    public DashboardController(DashboardService dashboardService) {
        this.dashboardService = dashboardService;
    }

    @GetMapping("/kpis")
    public Object kpis() {
        return dashboardService.kpis();
    }

    @GetMapping("/agenda")
    public Object agenda(
            @RequestParam(required = false) String q,
            @RequestParam(required = false) LocalDate from,
            @RequestParam(required = false) LocalDate to,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.agenda(q, from, to, page, size);
    }

    @GetMapping("/audit-logs")
    public Object audits(
            @RequestParam(required = false) String q,
            @RequestParam(required = false) LocalDate from,
            @RequestParam(required = false) LocalDate to,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "50") int size
    ) {
        return dashboardService.audits(q, from, to, page, size);
    }
}
*/