package com.cmvr.web.controller.api;

import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.edge.client.model.EdgeCommonVO;
import com.cmvr.edge.client.model.microphone.EdgeMicrophoneVolumeVO;
import com.cmvr.edge.client.service.EdgeMicrophoneService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 麦克风管理
 */
@Api(tags = "边缘--麦克风")
@RestController
@RequestMapping("/api/Microphone")
@RequiredArgsConstructor
public class EdgeMicrophoneController {

    private final EdgeMicrophoneService microphoneService;

    @ApiOperation("获取麦克风状态")
    @PreAuthorize("@ss.hasPermi('system:microphone:query')")
    @GetMapping("/status")
    public AjaxResult getStatus(EdgeCommonVO edgeCommonVO) {
        return AjaxResult.success(microphoneService.getStatus(edgeCommonVO));
    }

    @ApiOperation("开始录音")
    @PreAuthorize("@ss.hasPermi('system:microphone:record')")
    @PostMapping("/start")
    public AjaxResult startRecord(EdgeCommonVO edgeCommonVO) {
        String filePath = microphoneService.startRecord(edgeCommonVO);
        return AjaxResult.success(filePath);
    }

    @ApiOperation("停止录音")
    @PreAuthorize("@ss.hasPermi('system:microphone:stop')")
    @PostMapping("/stop")
    public AjaxResult stopRecord(EdgeCommonVO edgeCommonVO) {
        microphoneService.stopRecord(edgeCommonVO);
        return AjaxResult.success();
    }

    @ApiOperation("暂停录音")
    @PreAuthorize("@ss.hasPermi('system:microphone:pause')")
    @PostMapping("/pause")
    public AjaxResult pauseRecord(EdgeCommonVO edgeCommonVO) {
        microphoneService.pauseRecord(edgeCommonVO);
        return AjaxResult.success();
    }

    @ApiOperation("恢复录音")
    @PreAuthorize("@ss.hasPermi('system:microphone:resume')")
    @PostMapping("/resume")
    public AjaxResult resumeRecord(EdgeCommonVO edgeCommonVO) {
        microphoneService.resumeRecord(edgeCommonVO);
        return AjaxResult.success();
    }

    @ApiOperation("设置音量")
    @PreAuthorize("@ss.hasPermi('system:microphone:volume')")
    @PostMapping("/volume")
    public AjaxResult setVolume(EdgeMicrophoneVolumeVO edgeMicrophoneVolumeVO) {
        microphoneService.setVolume(edgeMicrophoneVolumeVO);
        return AjaxResult.success();
    }

    @ApiOperation("获取音量")
    @PreAuthorize("@ss.hasPermi('system:microphone:volume')")
    @GetMapping("/volume")
    public AjaxResult getVolume(EdgeCommonVO edgeCommonVO) {
        return AjaxResult.success(microphoneService.getVolume(edgeCommonVO));
    }
} 