package com.red.circle.external.inner.service.message.impl;

import com.red.circle.external.infra.common.PhoneSms;
import com.red.circle.external.inner.model.cmd.message.SendSmsCmd;
import com.red.circle.external.inner.service.message.PhoneSmsService;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.PhoneErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 手机相关服务 实现.
 *
 * @author pengliang on 2021/3/25
 */
@Service
@RequiredArgsConstructor
public class PhoneSmsServiceImpl implements PhoneSmsService {

  private final PhoneSms phoneSms;

  @Override
  public void sendCode(SendSmsCmd cmd) {
    // cmd.code & cmd.codeType: 没有实现， 默认只发验证码
    phoneSms.sendCode(cmd.getPhonePrefix(), cmd.getPhoneNumber());
  }

  @Override
  public boolean checkCode(SendSmsCmd cmd) {
    boolean res = phoneSms.checkCode(cmd.getPhonePrefix(), cmd.getPhoneNumber(), cmd.getCode());
    ResponseAssert.isTrue(PhoneErrorCode.VERIFICATION_CODE_NOT_MATCH, res);
    return res;
  }

}
