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

import com.qmth.boot.core.retrofit.utils.SignatureInfo;
import com.qmth.boot.core.sms.api.SmsApiClient;
import com.qmth.boot.core.sms.model.SmsConstants;
import com.qmth.boot.core.sms.model.SmsSendRequest;
import com.qmth.boot.core.sms.model.SmsSendResponse;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Service
public class SmsService {

    private SmsApiClient smsApiClient;

    public SmsService(SmsApiClient smsApiClient) {
        this.smsApiClient = smsApiClient;
    }

    /**
     * 发送普通短信
     *
     * @param request
     * @return
     */
    public SmsSendResponse sendSms(@Validated SmsSendRequest request) {
        return smsApiClient.sendSms(request);
    }

    /**
     * 使用机构鉴权发送普通短信
     *
     * @param request
     * @return
     */
    public SmsSendResponse sendSms(@NotNull SignatureInfo signature, @Validated SmsSendRequest request) {
        return smsApiClient.sendSms(signature, request);
    }

    /**
     * 往指定服务地址发送普通短信
     *
     * @param server  以http或https开头的服务地址，调用时自动拼接/api/sms/send相对路径
     * @param request
     * @return
     */
    public SmsSendResponse sendSms(@NotBlank String server, @Validated SmsSendRequest request) {
        return smsApiClient.sendSms(server + SmsConstants.API_PATH_SEND_SMS, request);
    }
}
