package com.fuyuanshen.app.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.fuyuanshen.common.idempotent.annotation.RepeatSubmit;
import com.fuyuanshen.common.log.annotation.Log;
import com.fuyuanshen.common.web.core.BaseController;
import com.fuyuanshen.common.mybatis.core.page.PageQuery;
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.log.enums.BusinessType;
import com.fuyuanshen.common.excel.utils.ExcelUtil;
import com.fuyuanshen.equipment.domain.vo.AppOperationVideoVo;
import com.fuyuanshen.equipment.domain.bo.AppOperationVideoBo;
import com.fuyuanshen.equipment.service.IAppOperationVideoService;
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;

/**
 * 操作视频
 *
 * @author Lion Li
 * @date 2025-07-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/app/operationVideo")
public class AppOperationVideoController extends BaseController {

    private final IAppOperationVideoService appOperationVideoService;

    /**
     * 查询操作视频列表
     */
    @SaCheckPermission("app:operationVideo:list")
    @GetMapping("/list")
    public TableDataInfo<AppOperationVideoVo> list(AppOperationVideoBo bo, PageQuery pageQuery) {
        return appOperationVideoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出操作视频列表
     */
    @SaCheckPermission("app:operationVideo:export")
    @Log(title = "操作视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppOperationVideoBo bo, HttpServletResponse response) {
        List<AppOperationVideoVo> list = appOperationVideoService.queryList(bo);
        ExcelUtil.exportExcel(list, "操作视频", AppOperationVideoVo.class, response);
    }

    /**
     * 获取操作视频详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("app:operationVideo:query")
    @GetMapping("/{id}")
    public R<AppOperationVideoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(appOperationVideoService.queryById(id));
    }

    /**
     * 新增操作视频
     */
    @SaCheckPermission("app:operationVideo:add")
    @Log(title = "操作视频", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppOperationVideoBo bo) {
        return toAjax(appOperationVideoService.insertByBo(bo));
    }

    /**
     * 修改操作视频
     */
    @SaCheckPermission("app:operationVideo:edit")
    @Log(title = "操作视频", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppOperationVideoBo bo) {
        return toAjax(appOperationVideoService.updateByBo(bo));
    }

    /**
     * 删除操作视频
     *
     * @param ids 主键串
     */
    @SaCheckPermission("app:operationVideo:remove")
    @Log(title = "操作视频", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(appOperationVideoService.deleteWithValidByIds(List.of(ids), true));
    }
}
