package com.ycwl.basic.controller.pc;

import com.github.pagehelper.PageInfo;
import com.ycwl.basic.model.pc.extraDevice.req.ExtraDevicePageQueryReq;
import com.ycwl.basic.model.pc.extraDevice.resp.ExtraDeviceRespVO;
import com.ycwl.basic.service.pc.ExtraDeviceService;
import com.ycwl.basic.utils.ApiResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 外部设备管理控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/extra_device/v1")
@RequiredArgsConstructor
public class ExtraDeviceController {

    private final ExtraDeviceService extraDeviceService;

    /**
     * 分页查询外部设备列表
     *
     * @param req 查询请求参数，包含scenicId(可选)、pageNum、pageSize
     * @return 分页查询结果，包含设备ID、景区ID、景区名称、设备名称、标识、状态、心跳时间、在线状态
     */
    @PostMapping("/page")
    public ApiResponse<PageInfo<ExtraDeviceRespVO>> page(@RequestBody ExtraDevicePageQueryReq req) {
        log.info("分页查询外部设备列表, scenicId: {}, pageNum: {}, pageSize: {}",
                req.getScenicId(), req.getPageNum(), req.getPageSize());

        PageInfo<ExtraDeviceRespVO> pageInfo = extraDeviceService.pageQuery(req);

        log.info("外部设备列表查询完成, total: {}, pages: {}",
                pageInfo.getTotal(), pageInfo.getPages());

        return ApiResponse.success(pageInfo);
    }
}
