package com.fuyuanshen.app.controller.device.bjq;

import com.fuyuanshen.app.domain.bo.AppPersonnelInfoBo;
import com.fuyuanshen.app.domain.dto.AppDeviceLogoUploadDto;
import com.fuyuanshen.app.domain.dto.DeviceInstructDto;
import com.fuyuanshen.app.domain.vo.AppDevice6075DetailVo;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessAnnotation;
import com.fuyuanshen.common.ratelimiter.annotation.FunctionAccessBatcAnnotation;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.equipment.domain.dto.AppDeviceSendMsgBo;
import com.fuyuanshen.web.service.device.DeviceBJQ6075BizService;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * BJQ6331便携式工作灯
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/BJQ6331/device")
public class AppDeviceBJQ6331Controller extends BaseController {

    private final DeviceBJQ6075BizService appDeviceService6075;


    /**
     * 获取设备详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<AppDevice6075DetailVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
        return R.ok(appDeviceService6075.getInfo(id));
    }


    /**
     * 人员信息登记 1
     */
    @PostMapping(value = "/registerPersonInfo")
    public R<Void> registerPersonInfo(@Validated(AddGroup.class) @RequestBody AppPersonnelInfoBo bo) {
        return toAjax(appDeviceService6075.registerPersonInfo(bo));
    }


    /**
     * 发送信息 2
     */
    @PostMapping(value = "/sendMessage")
    @FunctionAccessBatcAnnotation(value = "sendMessage", timeOut = 30, batchMaxTimeOut = 40)
    public R<Void> sendMessage(@RequestBody AppDeviceSendMsgBo bo) {
        return toAjax(appDeviceService6075.sendMessage(bo));
    }


    /**
     * 发送报警信息 3
     */
    @PostMapping(value = "/sendAlarmMessage")
    @FunctionAccessBatcAnnotation(value = "sendAlarmMessage", timeOut = 5, batchMaxTimeOut = 10)
    public R<Void> sendAlarmMessage(@RequestBody AppDeviceSendMsgBo bo) {
        return toAjax(appDeviceService6075.sendAlarmMessage(bo));
    }


    /**
     * 上传设备logo图片 4
     */
    @PostMapping("/uploadLogo")
    @FunctionAccessAnnotation("uploadLogo")
    public R<Void> upload(@Validated @ModelAttribute AppDeviceLogoUploadDto bo) {

        MultipartFile file = bo.getFile();
        if (file.getSize() > 1024 * 1024 * 2) {
            return R.warn("图片不能大于2M");
        }
        appDeviceService6075.uploadDeviceLogo(bo);

        return R.ok();
    }


    /**
     * 灯光模式 5
     * （主光模式）
     * 0（关闭灯光），1（强光），2（超强光）,  3（工作光）, 4（节能光），5（爆闪），6（SOS）
     */
    @PostMapping("/lightModeSettings")
    public R<Void> lightModeSettings(@RequestBody DeviceInstructDto params) {
        appDeviceService6075.lightModeSettings(params);
        return R.ok();
    }


    /**
     * 灯光模式 6
     * （辅光模式）
     * 0（关闭灯光），1（泛光），2（泛光爆闪）,  3（警示灯）, 4（警示灯/泛光）
     */
    @PostMapping("/auxiliaryLightModeSettings")
    public R<Void> auxiliaryLightModeSettings(@RequestBody DeviceInstructDto params) {
        appDeviceService6075.lightModeSettings(params);
        return R.ok();
    }


    /**
     * 灯光亮度设置 7
     */
    @PostMapping("/lightBrightnessSettings")
    public R<Void> lightBrightnessSettings(@RequestBody DeviceInstructDto params) {
        appDeviceService6075.lightBrightnessSettings(params);
        return R.ok();
    }

    /**
     * 激光模式设置 8
     */
    @PostMapping("/laserModeSettings")
    public R<Void> laserModeSettings(@RequestBody DeviceInstructDto params) {
        appDeviceService6075.laserModeSettings(params);
        return R.ok();
    }


    /**
     * 声光报警模式设置 9
     * Sound and light alarm
     */
    @PostMapping("/salaModeSettings")
    public R<Void> salaModeSettings(@RequestBody DeviceInstructDto params) {
        appDeviceService6075.laserModeSettings(params);
        return R.ok();
    }


    /**
     * 获取设备分享详细信息
     *
     * @param id 主键
     */
    @GetMapping("/getShareInfo/{id}")
    public R<AppDevice6075DetailVo> getShareInfo(@NotNull(message = "主键不能为空")
                                                 @PathVariable Long id) {
        return R.ok(appDeviceService6075.getInfo(id));
    }


}
