package com.fuyuanshen.web.controller.device;


import com.fuyuanshen.app.domain.AppPersonnelInfoRecords;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.DeviceLog;
import com.fuyuanshen.equipment.domain.vo.DeviceAlarmVo;
import com.fuyuanshen.equipment.domain.vo.WebDeviceVo;
import com.fuyuanshen.web.service.WEBDeviceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: WY
 * @Date: 2025/5/16
 **/
@Slf4j
@Tag(name = "web:设备管理", description = "web:设备管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/device")
public class WEBDeviceController extends BaseController {

    private final WEBDeviceService deviceService;


    /**
     * @param id
     * @return
     * @ModelAttribute 主要用于将请求参数绑定到 Java 对象上，它会从 HTTP 请求的查询参数（Query Parameters）
     * 或表单数据（Form Data）中提取值，并自动填充到指定的对象属性中。
     */
    // @Log("解绑设备")
    @Operation(summary = "WEB端解绑设备")
    @DeleteMapping(value = "/unbind")
    public R<Void> unbindDevice(Long id, Long userId) {
        return toAjax(deviceService.webUnBindDevice(id, userId));
    }


    /**
     * 设备详情
     *
     * @param id
     * @return
     */
    @Operation(summary = "设备详情")
    @GetMapping(value = "/pc/detail/{id}")
    public R<WebDeviceVo> getDeviceDetail(@PathVariable Long id) {
        WebDeviceVo device = deviceService.getDevice(id);
        return R.ok(device);
    }


    /**
     * 设备用户详情
     *
     * @param deviceId
     * @return
     */
    @Operation(summary = "设备用户详情")
    @GetMapping(value = "/getDeviceUser/{deviceId}")
    public R<List<AppPersonnelInfoRecords>> getDeviceUser(@PathVariable Long deviceId) {
        List<AppPersonnelInfoRecords> device = deviceService.getDeviceUser(deviceId);
        return R.ok(device);
    }


    /**
     * 设备操作记录
     *
     * @param deviceId
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Operation(summary = "设备操作记录")
    @GetMapping(value = "/getOperationRecord/{deviceId}")
    public TableDataInfo<DeviceLog> getOperationRecord(@PathVariable Long deviceId,
                                                 @RequestParam(required = false) String startTime,
                                                 @RequestParam(required = false) String endTime,
                                                       PageQuery pageQuery) {
        TableDataInfo<DeviceLog> device = deviceService.getOperationRecord(deviceId, startTime, endTime,pageQuery);
        return device;
    }


    /**
     * 设备告警记录
     *
     * @param deviceId
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    @Operation(summary = "设备告警记录")
    @GetMapping(value = "/getAlarmRecord/{deviceId}")
    public TableDataInfo<DeviceAlarmVo> getAlarmRecord(@PathVariable Long deviceId,
                                                       @RequestParam(required = false) String startTime,
                                                       @RequestParam(required = false) String endTime,
                                                       PageQuery pageQuery) {
        return deviceService.getAlarmRecord(deviceId, startTime, endTime, pageQuery);
    }


}


