package com.limap.common.utils.ali.iot;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class IotClient {

	private static String accessKeyID ;

	private static String accessKeySecret ;

	private static String regionId;

    private static String domain;

    private static String version;

    private static String productCode;

    public static DefaultAcsClient getClient() {
		DefaultAcsClient client = null;
		try {
			IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyID, accessKeySecret);
			DefaultProfile.addEndpoint(regionId, regionId, productCode,domain);
			// 初始化client
			client = new DefaultAcsClient(profile);

		} catch (Exception e) {
			LogUtil.print("初始化client失败！exception:" + e.getMessage());
		}
		return client;
	}

	public String getAccessKeyID() {
		return accessKeyID;
	}

	@Value("${ali.accessKeyId}")
	public void setAccessKeyID(String accessKeyID) {
		IotClient.accessKeyID = accessKeyID;
	}

	public String getAccessKeySecret() {
		return accessKeySecret;
	}

	@Value("${ali.accessKeySecret}")
	public void setAccessKeySecret(String accessKeySecret) {
		IotClient.accessKeySecret = accessKeySecret;
	}

	public String getRegionId() {
		return regionId;
	}

	@Value("${ali.iot.regionId}")
	public void setRegionId(String regionId) {
		IotClient.regionId = regionId;
	}

	public static String getDomain() {
		return domain;
	}

	@Value("${ali.iot.domain}")
	public void setDomain(String domain) {
		IotClient.domain = domain;
	}

	public static String getVersion() {
		return version;
	}

	@Value("${ali.iot.version}")
	public void setVersion(String version) {
		IotClient.version = version;
	}

	public String getProductCode() {
		return productCode;
	}

	@Value("${ali.iot.productCode}")
	public void setProductCode(String productCode) {
		IotClient.productCode = productCode;
	}
}
