package com.nbport.zgwl.contractpush.controller;

import com.nbport.zgwl.common.R;
import com.nbport.zgwl.contractpush.dto.ApproveQueryRequestDTO;
import com.nbport.zgwl.contractpush.dto.ApproveViewUrlRequestDTO;
import com.nbport.zgwl.contractpush.dto.PushPayloadDTO;
import com.nbport.zgwl.contractpush.dto.PushTokenRequestDTO;
import com.nbport.zgwl.contractpush.service.DataCollectionPushService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 数据采集推送相关接口
 * 对应《数据采集接口规范V3.0》
 */
@RestController
@RequestMapping("/contract/push/data-collection")
public class DataCollectionPushController {

    private final DataCollectionPushService dataCollectionPushService;

    public DataCollectionPushController(DataCollectionPushService dataCollectionPushService) {
        this.dataCollectionPushService = dataCollectionPushService;
    }

    @GetMapping("/token")
    public R<Map<String, Object>> getToken(PushTokenRequestDTO requestDTO) {
        return R.success(dataCollectionPushService.getToken(requestDTO));
    }

    @PostMapping("/upload")
    public R<Map<String, Object>> upload(@RequestPart("file") MultipartFile file,
                                         @RequestParam(value = "token", required = false) String token) {
        return R.success(dataCollectionPushService.upload(file, token));
    }

    @PostMapping("/opposites")
    public R<Map<String, Object>> collectOpposites(@RequestBody PushPayloadDTO requestDTO) {
        return R.success(dataCollectionPushService.collectOpposites(requestDTO));
    }

    @PostMapping("/ztbs")
    public R<Map<String, Object>> collectZtbs(@RequestBody PushPayloadDTO requestDTO) {
        return R.success(dataCollectionPushService.collectZtbs(requestDTO));
    }

    @PostMapping("/contract")
    public R<Map<String, Object>> collectContract(@RequestBody PushPayloadDTO requestDTO) {
        return R.success(dataCollectionPushService.collectContract(requestDTO));
    }

    @PostMapping("/plan-feedback")
    public R<Map<String, Object>> collectPlanFeedback(@RequestBody PushPayloadDTO requestDTO) {
        return R.success(dataCollectionPushService.collectPlanFeedback(requestDTO));
    }

    @PostMapping("/close")
    public R<Map<String, Object>> collectContractClose(@RequestBody PushPayloadDTO requestDTO) {
        return R.success(dataCollectionPushService.collectContractClose(requestDTO));
    }

    @PostMapping("/archive")
    public R<Map<String, Object>> collectContractArchive(@RequestBody PushPayloadDTO requestDTO) {
        return R.success(dataCollectionPushService.collectContractArchive(requestDTO));
    }

    @PostMapping("/approve/query")
    public R<Map<String, Object>> queryApproveInfo(@RequestBody ApproveQueryRequestDTO requestDTO) {
        return R.success(dataCollectionPushService.queryApproveInfo(requestDTO));
    }

    @PostMapping("/approve/view-url")
    public R<Map<String, Object>> buildApproveViewUrl(@RequestBody ApproveViewUrlRequestDTO requestDTO) {
        return R.success(dataCollectionPushService.buildApproveViewUrl(requestDTO));
    }
}
