package com.fuyuanshen.app.controller;

import com.fuyuanshen.app.domain.AppDeviceVoice;
import com.fuyuanshen.app.domain.bo.AppDeviceVoiceBo;
import com.fuyuanshen.app.service.IAppDeviceVoiceService;
import com.fuyuanshen.common.core.domain.R;
import com.fuyuanshen.common.core.validate.AddGroup;
import com.fuyuanshen.common.core.validate.EditGroup;
import com.fuyuanshen.common.core.validate.QueryGroup;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import jakarta.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 设备语音Controller
 *
 * @author Lion Li
 * @date 2025-07-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/device/voice")
public class AppDeviceVoiceController extends BaseController {
    
    private final IAppDeviceVoiceService appDeviceVoiceService;

    /**
     * 查询设备语音列表
     */
    @GetMapping("/list")
    public TableDataInfo<AppDeviceVoice> list(AppDeviceVoiceBo bo, PageQuery pageQuery) {
        return appDeviceVoiceService.queryPageList(bo, pageQuery);
    }

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

    /**
     * 新增设备语音
     */
    @PostMapping()
    public R<Void> add(@RequestPart("bo") @Validated(AddGroup.class) AppDeviceVoiceBo bo,
                       @RequestPart(value = "file", required = false) MultipartFile file) {
        return toAjax(appDeviceVoiceService.insertByBo(bo, file));
    }

    /**
     * 修改设备语音
     */
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppDeviceVoiceBo bo) {
        return toAjax(appDeviceVoiceService.updateByBo(bo));
    }

    /**
     * 删除设备语音
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotNull(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(appDeviceVoiceService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}