package com.tuoheng.admin.controller;

import com.tuoheng.admin.request.accident.*;
import com.tuoheng.admin.query.AccidentQuery;
import com.tuoheng.admin.service.accident.IAccidentService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 事故前端控制器
 *
 * @Author ChengWang
 * @Date 2023/3/2
 */
@RestController
@RequestMapping("/accident")
@Slf4j
public class AccidentController {

    @Autowired
    private IAccidentService accidentService;

    /**
     * 查询应急事故记录列表(分页)
     *
     * @param query
     * @return
     */
    @GetMapping("/index")
    public JsonResult index(AccidentQuery query) {
        return accidentService.index(query);
    }

    /**
     * 查询应急事故记录详情
     *
     * @param accidentId 事故id
     * @return
     */
    @GetMapping("/getInfo")
    public JsonResult getInfoByAccident(String accidentId) {
        return accidentService.getInfoByAccident(accidentId);
    }

    /**
     * 告警弹窗通知下发
     *
     * @return
     */
    @GetMapping("/notice")
    public JsonResult notice() {
        return accidentService.notice();
    }


    /**
     * 查询应急事故列表
     */
    @GetMapping("/list")
    public JsonResult getAccidentCardList(QueryAccidentListRequest request) {
//        log.info("进入查询应急事故分页列表接口, request={}", request);
        return accidentService.getAccidentCardList(request);
    }

    /**
     * 获取应急事故信息
     */
    @GetMapping(value = "/info/{id}")
    public JsonResult getInfo(@PathVariable("id") String id) {
//        log.info("进入查询应急事故详情接口, id={}", id);
        return accidentService.getAccidentInfo(id);
    }

    @PostMapping(value = "/create")
    public JsonResult create(@RequestBody AddAccidentRequest request) {
//        log.info("进入创建应急事故接口, request={}", request);
        return accidentService.create(request);
    }

    @PostMapping(value = "/forward")
    public JsonResult forward(@RequestBody AccidentForwardRequest request) {
//        log.info("进入前往接口, request={}", request);
        return accidentService.forward(request);
    }

    @PostMapping(value = "/continue/to/inspect")
    public JsonResult continueToInspect(@RequestBody ContinueToInspectRequest request) {
//        log.info("进入继续巡检接口, request={}", request);
        return accidentService.continueToInspect(request);
    }

    @PostMapping(value = "/record")
    public JsonResult record(@RequestBody AccidentRecordRequest request) {
//        log.info("进入应急事故记录接口, request={}", request);
        return accidentService.record(request);
    }

    @PostMapping(value = "/handle")
    public JsonResult handle(@RequestBody AccidentHandleRequest request) {
//        log.info("进入应急事故处理完成接口, request={}", request);
        return accidentService.handle(request);
    }

    /**
     * 查询应急任务状态 页面滑动展示
     * @param request
     * @return
     */
    @GetMapping("/getList")
    public JsonResult getList(QueryEmergencyListRequest request) {
        return accidentService.getAccList(request);
    }

    /**
     * 忽略
     *
     * @return
     */
    @PostMapping("/ignore/{id}")
    public JsonResult ignore(@PathVariable("id") String id){
        return accidentService.ignore(id);
    }

    /**
     * 修改任务状态为已完成
     * @param id
     * @return
     */
    @PutMapping("/status/{id}")
    public JsonResult updateStatus(@PathVariable("id") String id){
        log.info("进入修改事故状态接口,id={}",id);
        return accidentService.updateStatus(id);
    }

}
