package com.cpop.api.cloudDb.handler;

import com.alibaba.fastjson.JSONObject;
import com.cpop.api.cloudDb.core.constant.CloudDbUrl;
import com.cpop.api.cloudDb.core.dto.CloudBrandDto;
import com.cpop.common.utils.StringUtils;
import com.cpop.core.base.exception.UtilException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

/**
 * @author DB
 * @version 1.0.0
 * @since 2024-02-26 13:37
 */
@Component
public class CloudBrandHandler {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 更新品牌
     * @author DB
     * @since 2024/2/26
     * @param dto 云品牌对象
     */
    public void updateBrand(CloudBrandDto dto) {
        JSONObject jsonBody = new JSONObject();
        jsonBody.put("_type", "brandEdit");
        jsonBody.put("brandId", dto.getBrandCloudId());
        jsonBody.put("name", dto.getBrandName());
        JSONObject jsonObject = restTemplate.postForObject(CloudDbUrl.COMMON_USE_URL, jsonBody, JSONObject.class);
        if (jsonObject != null) {
            if (!jsonObject.getBoolean("success")) {
                throw new UtilException(jsonObject.getString("error"));
            }
        }
    }
}
