package com.huimv.video.video.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huimv.common.utils.Result;
import com.huimv.common.utils.ResultCode;
import com.huimv.video.video.entity.BaseSpecificVideo;
import com.huimv.video.video.entity.Camera;
import com.huimv.video.video.service.IBaseSpecificVideoService;
import com.huimv.video.video.service.ICameraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-12-20
 */
@RestController
@RequestMapping("/baseSpecificVideo")
public class  BaseSpecificVideoController {
    @Autowired
    IBaseSpecificVideoService baseSpecificVideoService;

    @Autowired
    ICameraService cameraService;

    @PostMapping("/add")
    public Result add(@RequestBody BaseSpecificVideo baseFarmX) {
        Camera byId = cameraService.getById(baseFarmX.getVideoId());
        baseFarmX.setVideoName(byId.getCameraName());
        baseSpecificVideoService.save(baseFarmX);
        return new Result(ResultCode.SUCCESS);
    }


    @GetMapping("/remove")
    public Result remove(@RequestParam(name = "id") Integer id) {
        baseSpecificVideoService.removeById(id);
        return new Result(ResultCode.SUCCESS);
    }

    @PostMapping("/update")
    public Result update(@RequestBody BaseSpecificVideo baseFarmX) {
        Camera byId = cameraService.getById(baseFarmX.getVideoId());
        baseFarmX.setVideoName(byId.getCameraName());
        baseSpecificVideoService.updateById(baseFarmX);
        return new Result(ResultCode.SUCCESS);
    }

    @GetMapping("/list")
    public Result list(@RequestParam(name = "farmId") Integer farmId) {

        return new Result(ResultCode.SUCCESS, baseSpecificVideoService.list(new QueryWrapper<BaseSpecificVideo>().eq("farm_id", farmId)));
    }

    @GetMapping("/listSpecif")
    public Result listSpecif(@RequestParam(name = "farmId") Integer farmId,
                             @RequestParam(name = "type") Integer type) {

        return new Result(ResultCode.SUCCESS, baseSpecificVideoService.listSpecif(farmId, type));
    }


}
