package org.springblade.file.feign;

import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.springblade.core.tool.api.R;
import org.springblade.file.pojo.dto.*;
import org.springblade.file.pojo.entity.Attachment;
import org.springblade.file.pojo.vo.*;
import org.springblade.thirdparty.ocr.pojo.vo.TransportCertificateVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.validation.annotation.Validated;
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.RequestParam;

import java.util.List;

/**
 * @author bfhuange
 * @date 2024/10/21
 */
@FeignClient(
        value = "blade-file",
        fallback = IFileClientFallback.class
)
public interface IFileClient {

    String API_PREFIX = "/feign/client/file";
    String ATTACHMENT = API_PREFIX + "/attachment";
    String ATTACHMENT_DETAIL = API_PREFIX + "/attachment-detail";
    String BUSINESS_ATTACHMENT_SAVE_REMOVE = API_PREFIX + "/businessAttachment-save-remove";
    String BUSINESS_ATTACHMENT_BATCH_SAVE_REMOVE = API_PREFIX + "/businessAttachment-batch-save-remove";
    String BUSINESS_ATTACHMENT_BATCH_SAVE_REMOVE_BY_PARAM = API_PREFIX + "/businessAttachment-batch-save-remove-by-param";
    String BUSINESS_ATTACHMENT_BATCH_SAVE_REMOVE_NO_BIZ_ID = API_PREFIX + "/businessAttachment-batch-save-remove-no-bizId";
    String BUSINESS_ATTACHMENT_REMOVE = API_PREFIX + "/businessAttachment-remove";
    String BUSINESS_ATTACHMENT_LIST = API_PREFIX + "/businessAttachment-list";
    String BUSINESS_UNZIP_TASK_SAVE = API_PREFIX + "/businessUnzipTask-save";
    String BUSINESS_UNZIP_TASK_UPDATE = API_PREFIX + "/businessUnzipTask-update";
    String BUSINESS_UNZIP_TASK_CANCEL = API_PREFIX + "/businessUnzipTask-cancel";
    String BUSINESS_UNZIP_TASK_REMOVE = API_PREFIX + "/businessUnzipTask-remove";
    String BUSINESS_UNZIP_TASK_LIST = API_PREFIX + "/businessUnzipTask-list";
    String BUSINESS_UNZIP_DETAIL_LIST = API_PREFIX + "/businessUnzipDetail-list";
    String RECOGNITION_TRANSPORT_CERTIFICATE = API_PREFIX + "/recognitionTransportCertificate";
    String FILE_URLS = API_PREFIX + "/getFileUrls";

    /**
     * 获取附件，多个附件id用逗号分割
     *
     * @param id
     * @return List<Attachment>
     */
    @GetMapping(ATTACHMENT)
    R<List<Attachment>> getAttachment(@RequestParam("id") String id);

    /**
     * 获取附件详情
     *
     * @param id
     * @return List<Attachment>
     */
    @GetMapping(ATTACHMENT_DETAIL)
    R<AttachmentDetailVO> getAttachmentDetail(@RequestParam("id") Long id);

    /**
     * 保存并删除业务附件，remove为true，先用bizId删除，再新增
     *
     * @param param
     * @return
     */
    @PostMapping(BUSINESS_ATTACHMENT_SAVE_REMOVE)
    R saveAndRemoveBusinessAttachment(@RequestBody @Validated BusinessAttachmentBatchAddDTO param);

    /**
     * 批量保存并删除业务附件，先删除附件，再新增，业务id为空，从params中获取bizId，先删除
     *
     * @param params 参数为空不新增
     * @param bizId  业务id
     * @return
     */
    @PostMapping(BUSINESS_ATTACHMENT_BATCH_SAVE_REMOVE)
    R batchSaveAndRemoveBusinessAttachment(@RequestBody List<@Valid BusinessAttachmentAddDTO> params, @RequestParam(value = "bizId", required = false) Long bizId);

    /**
     * 批量保存并删除业务附件，deleteParam为空，从params获取bizId删除，不为空，使用bizIds和bizCodes删除附件，bizCodes为空删除所有bizIds的附件
     *  deleteParam 中 delete 为false，不删除
     *
     * @param params 参数为空不新增
     * @param deleteParam  删除参数，支持只删除业务编码参数的附件
     * @return
     */
    @PostMapping(BUSINESS_ATTACHMENT_BATCH_SAVE_REMOVE_BY_PARAM)
    R batchSaveAndRemoveByParamBusinessAttachment(@RequestBody List<@Valid BusinessAttachmentAddDTO> params, @Valid @SpringQueryMap BusinessAttachmentDeleteDTO deleteParam);

    /**
     * 批量保存并删除业务附件，从参数中提取所有bizId
     *
     * @param params 参数
     * @return
     */
    @PostMapping(BUSINESS_ATTACHMENT_BATCH_SAVE_REMOVE_NO_BIZ_ID)
    R batchSaveAndRemoveBusinessAttachment(@RequestBody List<@Valid BusinessAttachmentAddDTO> params);

    /**
     * 根据业务id删除业务附件
     *
     * @param bizId
     * @return
     */
    @PostMapping(BUSINESS_ATTACHMENT_REMOVE)
    R removeBusinessAttachment(@NotNull(message = "业务id不能为空") @RequestParam(value = "bizId", required = false) Long bizId);

    /**
     * 查询业务附件列表
     *
     * @param param
     * @return
     */
    @PostMapping(BUSINESS_ATTACHMENT_LIST)
    R<List<BusinessAttachmentVO>> getBusinessAttachments(@Validated @RequestBody BusinessAttachmentQueryDTO param);

    /**
     *  保存业务解压任务
     * @param param
     * @return
     */
    @PostMapping(BUSINESS_UNZIP_TASK_SAVE)
    R saveBusinessUnzipTask(@Validated @RequestBody BusinessUnzipTaskAddDTO param);

    /**
     *  更新业务解压任务（重新上传）
     * @param param
     * @return
     */
    @PostMapping(BUSINESS_UNZIP_TASK_UPDATE)
    R updateBusinessUnzipTask(@Validated @RequestBody BusinessUnzipTaskUpdateDTO param);

    /**
     *  取消业务解压任务
     * @param bizId
     * @return
     */
    @PostMapping(BUSINESS_UNZIP_TASK_CANCEL)
    R cancelBusinessUnzipTask(@NotNull(message = "业务id不能为空") @RequestParam("bizId") Long bizId);

    /**
     *  删除业务解压任务
     * @param bizId
     * @return
     */
    @PostMapping(BUSINESS_UNZIP_TASK_REMOVE)
    R removeBusinessUnzipTask(@NotNull(message = "业务id不能为空") @RequestParam("bizId") Long bizId);

    /**
     *  根据业务id列表查询业务解压任务列表
     * @param bizIds
     * @return
     */
    @PostMapping(BUSINESS_UNZIP_TASK_LIST)
    R<List<BusinessUnzipTaskListVO>> getBusinessUnzipTasksByBizIds(@Validated @NotEmpty(message = "业务id列表不能为空") @RequestBody List<Long> bizIds);

    /**
     *  查询解压明细列表
     * @param bizId
     * @return
     */
    @GetMapping(BUSINESS_UNZIP_DETAIL_LIST)
    R<List<BusinessUnzipDetailListVO>> queryBusinessUnzipDetail(@NotNull(message = "业务id不能为空") @RequestParam("bizId") Long bizId);

    /**
     * 识别车辆运输凭证
     *
     * @param param 同一车牌文件夹下的附件objectKey列表
     * @return
     */
    @PostMapping(RECOGNITION_TRANSPORT_CERTIFICATE)
    R<TransportCertificateVO> recognitionTransportCertificates(@Validated @RequestBody FileCertificateBatchRecognitionDTO param);

    /**
     *  批量获取附件下载地址
     * @param param
     * @return
     */
    @PostMapping(FILE_URLS)
    R<List<FileUrlVO>> getFileUrls(@Validated @RequestBody IdsDTO param);
}
