// ============================================================
// IAuthRepository — 认证仓库接口（域层）
//
// 实现位于 data/ 层，域层不依赖任何具体实现。
// ============================================================

import '../entities/auth_session.dart';
import '../../../../core/services/auth_service.dart' show SmsCodeType, EmailCodeType;

export '../../../../core/services/auth_service.dart' show SmsCodeType, EmailCodeType;

abstract class IAuthRepository {
  // ── 会话恢复 ────────────────────────────────────────────────
  /// 从安全存储恢复上次会话；返回 null 表示无会话
  Future<AuthSession?> restoreSession();

  // ── 密码登录 ─────────────────────────────────────────────────
  Future<AuthSession> loginByPassword({
    required String identifier,
    required String password,
    String? deviceInfo,
  });

  // ── SMS 验证码登录 ────────────────────────────────────────────
  Future<AuthSession> loginByPhone({
    required String phone,
    required String smsCode,
    String? deviceInfo,
  });

  // ── 邮件验证码登录 ────────────────────────────────────────────
  Future<AuthSession> loginByEmail({
    required String email,
    required String emailCode,
    String? deviceInfo,
  });

  // ── 第三方登录 ────────────────────────────────────────────────
  Future<AuthSession> loginByWechat({
    required String code,
    String? referralCode,
    String? deviceInfo,
  });

  Future<AuthSession> loginByAlipay({
    required String authCode,
    String? referralCode,
    String? deviceInfo,
  });

  Future<AuthSession> loginByGoogle({
    required String idToken,
    String? referralCode,
    String? deviceInfo,
  });

  Future<AuthSession> loginByApple({
    required String identityToken,
    String? displayName,
    String? referralCode,
    String? deviceInfo,
  });

  // ── 注册 ──────────────────────────────────────────────────────
  Future<AuthSession> register({
    required String phone,
    required String smsCode,
    required String password,
    String? nickname,
    String? referralCode,
  });

  Future<AuthSession> registerByEmail({
    required String email,
    required String emailCode,
    required String password,
    String? nickname,
    String? referralCode,
  });

  // ── 登出 ──────────────────────────────────────────────────────
  Future<void> logout();

  // ── 验证码 ────────────────────────────────────────────────────
  Future<int> sendSmsCode(String phone, SmsCodeType type);
  Future<int> sendEmailCode(String email, EmailCodeType type);

  // ── 密码管理 ─────────────────────────────────────────────────
  Future<void> resetPassword({
    required String phone,
    required String smsCode,
    required String newPassword,
  });

  Future<void> resetPasswordByEmail({
    required String email,
    required String emailCode,
    required String newPassword,
  });

  Future<void> changePassword({
    required String oldPassword,
    required String newPassword,
  });

  Future<void> changePhone({
    required String newPhone,
    required String newSmsCode,
  });

  // ── 支付宝工具 ────────────────────────────────────────────────
  Future<String> getAlipayAuthString();

  // ── 推荐码 ────────────────────────────────────────────────────
  Future<bool> validateReferralCode(String code);
}
