/**
 * 20241029 ©WANGKANG 1686617586@qq.com
 */

package com.taais.biz.controller;

import java.io.IOException;
import java.util.List;

import com.taais.biz.domain.AddEvaluate;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.taais.common.core.core.domain.CommonResult;
import com.taais.common.excel.utils.ExcelUtil;
import com.taais.common.log.annotation.Log;
import com.taais.common.log.enums.BusinessType;
import com.taais.common.web.annotation.RepeatSubmit;
import com.taais.common.web.core.BaseController;
import jakarta.annotation.Resource;
import com.taais.biz.domain.vo.TrackSequenceVo;
import com.taais.biz.domain.bo.TrackSequenceBo;
import com.taais.biz.service.ITrackSequenceService;

import com.taais.common.core.core.page.PageResult;

/**
 * 注视轨迹序列Controller
 *
 * @author wangkang
 * 2024-09-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/trackSequence")
public class TrackSequenceController extends BaseController {
    @Resource
    private ITrackSequenceService trackSequenceService;

    /**
     * 查询注视轨迹序列列表
     */
    @SaCheckPermission("demo:trackSequence:list")
    @GetMapping("/list")
    public CommonResult<PageResult<TrackSequenceVo>> list(TrackSequenceBo trackSequenceBo) {
        return CommonResult.success(trackSequenceService.selectPage(trackSequenceBo));
    }

    /**
     * 导出注视轨迹序列列表
     */
    @SaCheckPermission("demo:trackSequence:export")
    @Log(title = "注视轨迹序列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrackSequenceBo trackSequenceBo) {
        List<TrackSequenceVo> list = trackSequenceService.selectList(trackSequenceBo);
        ExcelUtil.exportExcel(list, "注视轨迹序列", TrackSequenceVo.class, response);
    }

    /**
     * 获取注视轨迹序列详细信息
     */
    @SaCheckPermission("demo:trackSequence:query")
    @GetMapping(value = "/{id}")
    public CommonResult<TrackSequenceVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(trackSequenceService.selectById(id));
    }

    /**
     * 新增注视轨迹序列
     */
    @SaCheckPermission("demo:trackSequence:add")
    @Log(title = "注视轨迹序列", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult add(@Validated @RequestBody TrackSequenceBo trackSequenceBo) {
        return trackSequenceService.insert(trackSequenceBo);
    }

    /**
     * 修改注视轨迹序列
     */
    @SaCheckPermission("demo:trackSequence:edit")
    @Log(title = "注视轨迹序列", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody TrackSequenceBo trackSequenceBo) {
        Boolean updated = trackSequenceService.update(trackSequenceBo);
        if (!updated) {
            return CommonResult.fail("修改注视轨迹序列记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除注视轨迹序列
     */
    @SaCheckPermission("demo:trackSequence:remove")
    @Log(title = "注视轨迹序列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = trackSequenceService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除注视轨迹序列记录失败!");
        }
        return CommonResult.success();
    }

    @GetMapping("/start/{id}")
    public CommonResult start(@PathVariable("id") Long id) {
        return trackSequenceService.start(id);
    }

    @GetMapping("/stop/{id}")
    public CommonResult stop(@PathVariable("id") Long id) {
        return trackSequenceService.stop(id);
    }

    @GetMapping("/zip/{id}")
    public ResponseEntity<org.springframework.core.io.Resource> zipFolder(@PathVariable("id") Long id) throws IOException {
        /**
         * 传VideoImage的ID
         */
        return trackSequenceService.zipImages(id);
    }

    @GetMapping("/log/{id}")
    public CommonResult getLog(@PathVariable("id") Long id) {
        return trackSequenceService.getLog(id);
    }

    @GetMapping("/detail/{id}")
    public CommonResult getDetail(@PathVariable("id") Long id) {
        return trackSequenceService.getDetail(id);
    }

    @PostMapping("/add_evaluate")
    public CommonResult addEvaluate(@RequestBody AddEvaluate addEvaluate) {
        return trackSequenceService.addEvaluate(addEvaluate);
    }

    @GetMapping("/model/{id}")
    public CommonResult getModelList(@PathVariable("id") Long id) {
        return trackSequenceService.getModelList(id);
    }
}
