package com.sckw.message.feign;

import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.BaseResult;
import com.sckw.message.api.feign.SmsApiService;
import com.sckw.message.api.model.GetSmsDto;
import com.sckw.message.api.model.SendSmsDto;
import com.sckw.message.model.bo.GetVerifyCodeBo;
import com.sckw.message.model.bo.SmsBo;
import com.sckw.message.service.SmsService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author xucaiqin
 * @date 2026-05-07 11:00:11
 */
@RestController
@Validated
public class SmsApiServiceImpl implements SmsApiService {
    @Resource
    private SmsService smsService;

    @Override
    public BaseResult<Object> getVerifyCode(GetSmsDto getSmsDto) {
        GetVerifyCodeBo getVerifyCodeBo = new GetVerifyCodeBo();
        getVerifyCodeBo.setMobile(getSmsDto.getMobile());
        getVerifyCodeBo.setBizType(getSmsDto.getBizType());
        getVerifyCodeBo.setDelete(getSmsDto.getDelete());
        return BaseResult.success(smsService.getCode(getVerifyCodeBo), "获取成功");
    }

    @Override
    public BaseResult<Object> sendVerifyCode(SendSmsDto sendSmsDto) {
        try {
            SmsBo smsBo = new SmsBo();
            smsBo.setPhone(sendSmsDto.getMobile());
            smsBo.setType(sendSmsDto.getBizType());
            smsService.sendVerifyCode(smsBo);
        } catch (Exception exception) {
            return BaseResult.failed(HttpStatus.GLOBAL_EXCEPTION_CODE, exception.getMessage());
        }
        return BaseResult.success("", "发送成功");
    }
}
