package com.xdap.self_development.feign;

import com.xdap.common.config.FeignConfig;
import com.xdap.self_development.domain.dto.AppTokenDTO;
import com.xdap.self_development.domain.dto.FileUploadDTO;
import com.xdap.self_development.domain.dto.UserTokenDT0;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@FeignClient(
        name = "apaas-client",
        url = "${apaas.token.url}",
        configuration = FeignConfig.class
)
public interface ApaasMyTokenFeign {
    // 获取应用凭证
    @PostMapping("/xdap-open/token")
    AppTokenDTO getAppToken(
            @RequestParam("grant_type") String grantType,
            @RequestParam("client_id") String clientId,
            @RequestParam("client_secret") String clientSecret
    );

    // 获取用户凭证
    @GetMapping("/xdap-open/token/userToken")
    UserTokenDT0 getUserToken(
            @RequestParam("token") String token,
            @RequestParam("userId") String userId
    );

    // 上传文件
    @PostMapping(value = "/xdap-open/open/attachments/v1/simpleUploadFile",
            consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    FileUploadDTO uploadFile(
            @RequestHeader(value = "Authorization") String accessToken,

            @RequestPart("file") MultipartFile file,
            @RequestPart("uploadId") String uploadId,
            @RequestPart("tenantId") String tenantId,
            @RequestPart("userId") String userId
    );
}