import 'package:json_annotation/json_annotation.dart';
import 'package:networks_sdk/networks_sdk.dart';

import 'package:im_app/core/foundation/api_paths.dart';

part 'verify_otp_request.g.dart';

/// 校验验证码接口的响应（服务端 data 字段）。
///
/// `token` 是 vcode_token，用于后续 login-user 请求换取 access_token。
/// 纯 Dart 类，无需任何注解。`_$VerifyOtpResponseFromJson` 由生成器自动推导生成。
class VerifyOtpResponse {
  /// 验证令牌，传给登录接口换取 access_token
  final String token;

  const VerifyOtpResponse({required this.token});
}

/// # /app/api/auth/vcode/check — 校验手机验证码
///
/// 校验成功后返回 [VerifyOtpResponse.token]（即 vcode_token），
/// 用于 [LoginRequest] 的 `vcode_token` 字段。
///
/// ## 数据流位置
///
/// ```
/// AuthRepositoryImpl.verifyOtp(countryCode, contact, code)
///   → _client.executeRequest( ★ VerifyOtpRequest ★ )   ← 你在这里
///     → 服务端 POST /app/api/auth/vcode/check
///     → SDK 拆包 {code, message, data} envelope
///     ← ★ VerifyOtpResponse ★ — token 即 vcode_token
/// ```
@ApiRequest(
  path: ApiPaths.authVerifyOtp,
  method: HttpMethod.post,
  responseType: VerifyOtpResponse,
  requestType: ApiRequestType.login,
)
class VerifyOtpRequest extends ApiRequestable<VerifyOtpResponse>
    with _$VerifyOtpRequestApi {
  @JsonKey(name: 'country_code')
  final String countryCode;
  final String contact;

  /// 邮箱（手机号登录传空字符串）
  final String email;

  /// 用户输入的验证码
  final String code;

  /// type=1 表示手机号验证
  final int type;

  VerifyOtpRequest({
    required this.countryCode,
    required this.contact,
    required this.code,
    this.email = '',
    this.type = 1,
  });
}
