package com.aegis.web.controller.emergency.report;

import com.aegis.common.annotation.Log;
import com.aegis.common.core.controller.BaseController;
import com.aegis.common.core.domain.AjaxResult;
import com.aegis.common.core.page.TableDataInfo;
import com.aegis.common.enums.BusinessType;
import com.aegis.emergency.report.domain.ProvinceReport;
import com.aegis.emergency.report.dto.ProvinceReportRequest;
import com.aegis.emergency.report.service.IProvinceReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 省厅上报管理 Controller
 * 
 * @author aegis
 */
@Api(tags = "应急调度-省厅上报管理")
@RestController
@RequestMapping("/api/emergency/province-reports")
public class ProvinceReportController extends BaseController {

    @Autowired
    private IProvinceReportService provinceReportService;

    @ApiOperation("查询上报记录列表")
    @GetMapping("/list")
    public TableDataInfo list(ProvinceReport condition) {
        startPage();
        List<ProvinceReport> list = provinceReportService.listReports(condition);
        return getDataTable(list);
    }

    @ApiOperation("根据事件ID查询上报记录列表")
    @GetMapping("/event/{eventId}")
    public AjaxResult listByEvent(@PathVariable Long eventId) {
        ProvinceReport condition = new ProvinceReport();
        condition.setEventId(eventId);
        List<ProvinceReport> list = provinceReportService.listReports(condition);
        return success(list);
    }

    @ApiOperation("获取上报记录详情")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        ProvinceReport report = provinceReportService.getById(id);
        if (report == null) {
            return error("上报记录不存在或已删除");
        }
        return success(report);
    }

    @ApiOperation("提交上报")
    @Log(title = "省厅上报管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult submit(@RequestBody ProvinceReportRequest request) {
        ProvinceReport report = provinceReportService.submit(request);
        return success(report);
    }

    @ApiOperation("删除上报记录")
    @Log(title = "省厅上报管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(provinceReportService.removeByIds(Arrays.asList(ids)));
    }

}