package com.usky.vpp.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.vpp.service.VppReportInfoService;
import com.usky.vpp.service.vo.ReportAuditRequest;
import com.usky.vpp.service.vo.ReportDataSaveRequest;
import com.usky.vpp.service.vo.ReportPrefillVO;
import com.usky.vpp.service.vo.ReportRecordVO;
import com.usky.vpp.service.vo.ReportTaskCreateRequest;
import com.usky.vpp.service.vo.ReportTaskCreateResultVO;
import com.usky.vpp.service.vo.ReportTaskVO;
import com.usky.vpp.service.vo.ReportValidateResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 监管信息报送接口
 * <p>网关前缀: /prod-api/service-vpp/report</p>
 */
@RestController
@RequestMapping("/report")
public class ReportInfoController {

    @Autowired
    private VppReportInfoService vppReportInfoService;

    @GetMapping("/task")
    public ApiResult<CommonPage<ReportTaskVO>> pageTask(@RequestParam(required = false) Map<String, Object> params) {
        return ApiResult.success(vppReportInfoService.pageTask(params));
    }

    @PostMapping("/task")
    public ApiResult<ReportTaskCreateResultVO> createTask(@RequestBody ReportTaskCreateRequest body) {
        return ApiResult.success(vppReportInfoService.createTask(body));
    }

    @GetMapping("/record/{id}")
    public ApiResult<ReportRecordVO> getRecord(@PathVariable("id") Long id) {
        return ApiResult.success(vppReportInfoService.getRecord(id));
    }

    @GetMapping("/record/{id}/prefill")
    public ApiResult<ReportPrefillVO> prefill(@PathVariable("id") Long id) {
        return ApiResult.success(vppReportInfoService.prefill(id));
    }

    @PutMapping("/record/{id}/data")
    public ApiResult<Map<String, Object>> saveData(@PathVariable("id") Long id,
                                                   @RequestBody ReportDataSaveRequest body) {
        return ApiResult.success(vppReportInfoService.saveData(id, body));
    }

    @PostMapping("/record/{id}/validate")
    public ApiResult<ReportValidateResultVO> validateData(@PathVariable("id") Long id) {
        return ApiResult.success(vppReportInfoService.validateData(id));
    }

    @PostMapping("/record/{id}/submitAudit")
    public ApiResult<Map<String, Object>> submitAudit(@PathVariable("id") Long id) {
        return ApiResult.success(vppReportInfoService.submitAudit(id));
    }

    @PutMapping("/record/{id}/audit")
    public ApiResult<Void> audit(@PathVariable("id") Long id, @RequestBody ReportAuditRequest body) {
        vppReportInfoService.audit(id, body);
        return ApiResult.success();
    }

    @PostMapping("/record/{id}/submit")
    public ApiResult<ReportRecordVO> submit(@PathVariable("id") Long id) {
        return ApiResult.success(vppReportInfoService.submit(id));
    }

    @GetMapping("/history")
    public ApiResult<CommonPage<ReportRecordVO>> history(@RequestParam(required = false) Map<String, Object> params) {
        return ApiResult.success(vppReportInfoService.pageHistory(params));
    }
}
