package com.xy.xyaicpzs.controller;

import com.xy.xyaicpzs.common.ResultUtils;
import com.xy.xyaicpzs.common.response.ApiResponse;
import com.xy.xyaicpzs.service.SmsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信控制器
 */
@RestController
@RequestMapping("/sms")
@Tag(name = "短信接口", description = "提供短信验证码相关功能")
public class SmsController {

    @Autowired
    private SmsService smsService;

    /**
     * 发送短信验证码
     *
     * @param phoneNumber 手机号
     * @return 发送结果
     */
    @PostMapping("/sendCode")
    @Operation(summary = "发送短信验证码", description = "向指定手机号发送验证码，每个手机号每天最多发送3次")
    public ApiResponse<Boolean> sendVerificationCode(
            @Parameter(description = "手机号码", required = true) 
            @RequestParam String phoneNumber) {
        try {
            boolean success = smsService.sendVerificationCode(phoneNumber);
            if (success) {
                return ResultUtils.success(true);
            } else {
                return ResultUtils.error(40001, "发送验证码失败，请稍后重试或联系客服");
            }
        } catch (Exception e) {
            return ResultUtils.error(50000, "发送验证码异常：" + e.getMessage());
        }
    }
} 