package com.qmth.boot.core.sms.config;

import com.qmth.boot.core.retrofit.interfaces.CustomizeRetrofitConfiguration;
import com.qmth.boot.core.retrofit.interfaces.SignatureProvider;
import com.qmth.boot.core.solar.config.SolarProperties;
import com.qmth.boot.tools.signature.SignatureType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SmsApiConfiguration implements CustomizeRetrofitConfiguration {

    private static final Logger log = LoggerFactory.getLogger(SmsApiConfiguration.class);

    private SmsProperties smsProperties;

    private SolarProperties solarProperties;

    public SmsApiConfiguration(SmsProperties smsProperties, SolarProperties solarProperties) {
        this.smsProperties = smsProperties;
        this.solarProperties = solarProperties;
        log.info("Sms api client inited, server=" + smsProperties.getServer());
    }

    public String getBaseUrl() {
        return smsProperties.getServer();
    }

    public SignatureProvider getSignature() {
        return new SignatureProvider() {

            @Override
            public SignatureType getType() {
                return SignatureType.SECRET;
            }

            @Override
            public String getIdentity() {
                return solarProperties.getAccessKey();
            }

            @Override
            public String getSecret() {
                return solarProperties.getAccessSecret();
            }
        };
    }
}
