package com.erp.print.controller;

import com.erp.print.dto.request.PrintRecordQueryRequest;
import com.erp.common.core.model.ApiResponse;
import com.erp.common.core.model.PageResponse;
import com.erp.print.dto.response.PrintStatisticsResponse;
import com.erp.print.entity.PrintRecord;
import com.erp.print.service.PrintRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "打印记录查询")
@RestController
@RequestMapping("/api/print/records")
@RequiredArgsConstructor
public class PrintRecordController {

    private final PrintRecordService recordService;

    @Operation(summary = "分页查询打印记录")
    @GetMapping
    public ApiResponse<PageResponse<PrintRecord>> listRecords(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "20") Integer limit,
            PrintRecordQueryRequest request) {
        return ApiResponse.success(recordService.listRecords(page, limit, request));
    }

    @Operation(summary = "获取记录详情")
    @GetMapping("/{id}")
    public ApiResponse<PrintRecord> getRecord(@PathVariable Long id) {
        return ApiResponse.success(recordService.getRecordById(id));
    }

    @Operation(summary = "根据记录编号获取记录")
    @GetMapping("/no/{recordNo}")
    public ApiResponse<PrintRecord> getRecordByRecordNo(@PathVariable String recordNo) {
        return ApiResponse.success(recordService.getRecordByRecordNo(recordNo));
    }

    @Operation(summary = "获取打印统计")
    @GetMapping("/statistics")
    public ApiResponse<PrintStatisticsResponse> getStatistics() {
        return ApiResponse.success(recordService.getStatistics());
    }
}
