package org.wcs.serve.controller.app;

import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import org.wcs.model.vo.custom.BaseChartsDataItem;
import org.wcs.model.vo.custom.MultilineLineChartData;
import org.wcs.model.vo.serve.AppServeDataResponse;
import org.wcs.model.vo.serve.sys.QuerySystemInfoVo;
import org.wcs.serve.service.intf.IConfigService;
import org.wcs.serve.service.intf.ISystemService;

import java.util.List;

@RestController
@RequestMapping("/app/system")
@ResponseBody
@RequiredArgsConstructor
public class SystemController {


    private final ISystemService systemService;
    private final IConfigService configService;

    /**
     * 查询系统信息
     * @return 系统信息
     */
    @GetMapping("/querySystemInfo")
    public AppServeDataResponse<QuerySystemInfoVo> querySystemInfo(HttpServletRequest request) {
        return systemService.querySystemInfo(request);
    }

    /**
     * 获取配置
     * @param key 配置键
     * @return 配置值
     */
    @GetMapping("/queryConfigValue/{key}")
    public AppServeDataResponse<String> queryConfigValue(@PathVariable("key") String key) {
        return configService.queryConfigValue(key);
    }

    /**
     * 接收系统信息 ---- SSE 连接
     * @return 系统信息
     */
    @GetMapping(value = "/acceptInfo", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter acceptInfo() {
        return systemService.acceptInfo();
    }

    /**
     * 查询库存使用情况
     * @return 库存使用情况
     */
    @GetMapping("/queryStockUsage")
    public AppServeDataResponse<List<BaseChartsDataItem>> queryStockUsage(HttpServletRequest request) {
        return systemService.queryStockUsage(request);
    }

    /**
     * 获取今日入库出库数量
     * @return 今日入库出库数量
     */
    @GetMapping("/queryTodayInOutCount")
    public AppServeDataResponse<List<BaseChartsDataItem>> queryTodayInOutCount(HttpServletRequest request) {
        return systemService.queryTodayInOutCount(request);
    }

    /**
     * 获取近7天设备故障数量
     * @return 错误数量
     */
    @GetMapping("/querySevenDaysDeviceFailure")
    public AppServeDataResponse<List<BaseChartsDataItem>> queryDeviceErrorCountDay7(HttpServletRequest request) {
        return systemService.queryDeviceErrorCountDay7(request);
    }

    /**
     * 获取近7天入库出库数量
     * @return 入库出库数量
     */
    @GetMapping("/querySevenDaysInOutCount")
    public AppServeDataResponse<MultilineLineChartData> queryInOutCountDay7(HttpServletRequest request) {
        return systemService.queryInOutCountDay7(request);
    }



}
