package com.mmc.iuav.user.client;


import com.alibaba.fastjson2.JSONObject;
import com.mmc.iuav.response.ResultBody;
import com.mmc.iuav.response.ResultEnum;
import com.mmc.iuav.user.entity.CompanyInfoDO;
import com.mmc.iuav.user.model.vo.LicenseOrganizationsVO;
import com.mmc.iuav.user.model.vo.WalletUsersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

@Component
public class ImsClient {

    @Value("${iuav.ims.uri}")
    private String imsAppUri;

    @Autowired
    private RestTemplate restTemplate;

    public ResultBody insertOrganizations(CompanyInfoDO companyInfoDO, String token) {
        LicenseOrganizationsVO licenseOrganizationsVO = companyInfoDO.buildLicenseOrganizationsVO();
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add("token", token);
        HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(licenseOrganizationsVO), headers);
        ResponseEntity<ResultBody> responseEntity = restTemplate.exchange(imsAppUri + "/licence/background/insertOrg", HttpMethod.POST, entity, ResultBody.class);
        return responseEntity.getBody();
    }
}
