import '../../../../core/usecases/usecase.dart';
import '../../../../core/error/failures.dart';
import '../../domain/entities/otp_response.dart';
import '../../domain/repositories/auth_repository.dart';
import '../datasources/auth_remote_data_source.dart';

class AuthRepositoryImpl implements AuthRepository {
  final AuthRemoteDataSource remoteDataSource;

  AuthRepositoryImpl({
    required this.remoteDataSource,
  });

  @override
  Future<Result<OtpResponse>> sendOTP(String phoneNumber) async {
    try {
      final result = await remoteDataSource.sendOTP(phoneNumber);
      return Result.success(result);
    } catch (e) {
      return Result.failure(ServerFailure());
    }
  }

  @override
  Future<Result<bool>> verifyOTP(String otpCode, String phoneNumber) async {
    try {
      final result = await remoteDataSource.verifyOTP(otpCode, phoneNumber);
      return Result.success(result);
    } catch (e) {
      return Result.failure(ServerFailure());
    }
  }
}
