// ============================================================
// Login UseCases — 各种登录方式的用例
// ============================================================

import '../entities/auth_session.dart';
import '../repositories/auth_repository.dart';

// ── 密码登录 ────────────────────────────────────────────────

class LoginByPasswordParams {
  final String identifier;
  final String password;
  final String? deviceInfo;
  const LoginByPasswordParams({
    required this.identifier,
    required this.password,
    this.deviceInfo,
  });
}

class LoginByPasswordUseCase {
  final IAuthRepository _repository;
  const LoginByPasswordUseCase(this._repository);

  Future<AuthSession> call(LoginByPasswordParams params) {
    return _repository.loginByPassword(
      identifier: params.identifier,
      password: params.password,
      deviceInfo: params.deviceInfo,
    );
  }
}

// ── SMS 验证码登录 ────────────────────────────────────────────

class LoginByPhoneParams {
  final String phone;
  final String smsCode;
  final String? deviceInfo;
  const LoginByPhoneParams({
    required this.phone,
    required this.smsCode,
    this.deviceInfo,
  });
}

class LoginByPhoneUseCase {
  final IAuthRepository _repository;
  const LoginByPhoneUseCase(this._repository);

  Future<AuthSession> call(LoginByPhoneParams params) {
    return _repository.loginByPhone(
      phone: params.phone,
      smsCode: params.smsCode,
      deviceInfo: params.deviceInfo,
    );
  }
}

// ── 邮件验证码登录 ────────────────────────────────────────────

class LoginByEmailParams {
  final String email;
  final String emailCode;
  const LoginByEmailParams({required this.email, required this.emailCode});
}

class LoginByEmailUseCase {
  final IAuthRepository _repository;
  const LoginByEmailUseCase(this._repository);

  Future<AuthSession> call(LoginByEmailParams params) {
    return _repository.loginByEmail(email: params.email, emailCode: params.emailCode);
  }
}

// ── 微信登录 ──────────────────────────────────────────────────

class LoginByWechatParams {
  final String code;
  final String? referralCode;
  const LoginByWechatParams({required this.code, this.referralCode});
}

class LoginByWechatUseCase {
  final IAuthRepository _repository;
  const LoginByWechatUseCase(this._repository);

  Future<AuthSession> call(LoginByWechatParams params) {
    return _repository.loginByWechat(code: params.code, referralCode: params.referralCode);
  }
}

// ── 支付宝登录 ────────────────────────────────────────────────

class LoginByAlipayParams {
  final String authCode;
  final String? referralCode;
  const LoginByAlipayParams({required this.authCode, this.referralCode});
}

class LoginByAlipayUseCase {
  final IAuthRepository _repository;
  const LoginByAlipayUseCase(this._repository);

  Future<AuthSession> call(LoginByAlipayParams params) {
    return _repository.loginByAlipay(authCode: params.authCode, referralCode: params.referralCode);
  }
}

// ── Google 登录 ────────────────────────────────────────────────

class LoginByGoogleParams {
  final String idToken;
  final String? referralCode;
  const LoginByGoogleParams({required this.idToken, this.referralCode});
}

class LoginByGoogleUseCase {
  final IAuthRepository _repository;
  const LoginByGoogleUseCase(this._repository);

  Future<AuthSession> call(LoginByGoogleParams params) {
    return _repository.loginByGoogle(idToken: params.idToken, referralCode: params.referralCode);
  }
}

// ── Apple 登录 ────────────────────────────────────────────────

class LoginByAppleParams {
  final String identityToken;
  final String? displayName;
  final String? referralCode;
  const LoginByAppleParams({
    required this.identityToken,
    this.displayName,
    this.referralCode,
  });
}

class LoginByAppleUseCase {
  final IAuthRepository _repository;
  const LoginByAppleUseCase(this._repository);

  Future<AuthSession> call(LoginByAppleParams params) {
    return _repository.loginByApple(
      identityToken: params.identityToken,
      displayName: params.displayName,
      referralCode: params.referralCode,
    );
  }
}
