package com.jwipc.sys.constant;

import com.alibaba.fastjson2.JSONObject;
import com.dtflys.forest.annotation.*;
import com.jwipc.log.annotation.ApiOperateLog;
import com.jwipc.log.constant.ApiDirection;
import com.jwipc.log.constant.ThirdSysType;
import com.jwipc.sys.dto.FinancialShareApiResultDTO;
import com.jwipc.sys.dto.KingdeeInvoiceCloudApiArrayResultDTO;
import com.jwipc.sys.dto.KingdeeInvoiceCloudApiResultDTO;

/**
 * <p>
 *  发票云接口
 * </p>
 *
 * @author Chen Tianshi
 * @since 2025/10/13 13:38
 */
@BaseRequest(baseURL = "#{sys.kingdee.financial-share.host}")
public interface SysKingdeeInvoiceCloudClient {
    /**
     * 获取发票云助手App Token
     */
    @Post(
            url = "/api/getAppToken.do",
            contentType = "application/json; charset=UTF-8"
    )
    @ApiOperateLog(
            code = "GetAppToken",
            name = "获取金蝶App Token",
            direction = ApiDirection.SRM_TO_OTHER,
            thirdSysType = ThirdSysType.INVOICE_CLOUD
    )
    FinancialShareApiResultDTO getAppToken(@Body JSONObject body);

    /**
     * 获取发票云助手Access Token
     */
    @Post(
            url = "/api/login.do",
            contentType = "application/json; charset=UTF-8"
    )
    @ApiOperateLog(
            code = "GetAccessToken",
            name = "获取金蝶Access Token",
            direction = ApiDirection.SRM_TO_OTHER,
            thirdSysType = ThirdSysType.INVOICE_CLOUD
    )
    FinancialShareApiResultDTO getAccessToken(@Body JSONObject body);

    /**
     * 发票识别查验
     */
    @Post(
            url = "/kapi/app/rim/message",
            contentType = "application/json; charset=UTF-8"
    )
    @ApiOperateLog(
            code = "RecognitionCheck",
            name = "发票识别查验",
            direction = ApiDirection.SRM_TO_OTHER,
            thirdSysType = ThirdSysType.INVOICE_CLOUD
    )
    KingdeeInvoiceCloudApiArrayResultDTO recognitionCheck(@Query("access_token") String token, @Body JSONObject body);

    /**
     * 获取发票云eventCode
     */
    @Post(
            url = "/kapi/app/rim/message",
            contentType = "application/json; charset=UTF-8"
    )
    @ApiOperateLog(
            code = "GetEventCode",
            name = "获取发票云eventCode",
            direction = ApiDirection.SRM_TO_OTHER,
            thirdSysType = ThirdSysType.INVOICE_CLOUD
    )
    KingdeeInvoiceCloudApiResultDTO getEventCode(@Query("access_token") String token, @Body JSONObject body);

    /**
     * 删除发票云发票
     */
    @Post(
            url = "/kapi/app/rim/message",
            contentType = "application/json; charset=UTF-8"
    )
    @ApiOperateLog(
            code = "deleteInvoice",
            name = "删除发票云发票",
            direction = ApiDirection.SRM_TO_OTHER,
            thirdSysType = ThirdSysType.INVOICE_CLOUD
    )
    KingdeeInvoiceCloudApiResultDTO deleteInvoice(@Query("access_token") String token, @Body JSONObject body);

    /**
     * 删除发票云发票
     */
    @Post(
            url = "/kapi/app/rim/message",
            contentType = "application/json; charset=UTF-8"
    )
    @ApiOperateLog(
            code = "billSign",
            name = "发票云发票签收",
            direction = ApiDirection.SRM_TO_OTHER,
            thirdSysType = ThirdSysType.INVOICE_CLOUD
    )
    KingdeeInvoiceCloudApiResultDTO billSign(@Query("access_token") String token, @Body JSONObject body);

    /**
     * 下载发票云文件
     */
    @Get(
            url = "/attachment/download.do",
            dataType = "binary"
    )
    @ApiOperateLog(
            code = "AttachmentDownload",
            name = "发票云收票模块",
            direction = ApiDirection.SRM_TO_OTHER,
            thirdSysType = ThirdSysType.INVOICE_CLOUD
    )
    byte[] attachmentDownload(@Query("path") String filePath, @Query("access_token") String token);

    /**
     * 附件上传文件服务器并与单据的绑定
     * @param token token
     * @param body 请求参数
     * @return 结果
     */
    @LogEnabled(false)
    @Post(
            url = "/kapi/v2/m4p4/ap/api/uploadFileForBill",
            contentType = "multipart/form-data; charset=utf-8"
    )
    @ApiOperateLog(
            code = "UploadFileForBill",
            name = "附件上传文件服务器并与单据的绑定",
            direction = ApiDirection.SRM_TO_OTHER,
            thirdSysType = ThirdSysType.SHARE
    )
    FinancialShareApiResultDTO uploadFileForBill(@Query("access_token") String token,
                                                 @DataFile(value = "file", fileName = "${2}") byte[] bytes,
                                                 String filename,
                                                 @Body JSONObject body);
}
