import 'package:dartz/dartz.dart';
import 'package:food_delivery_client/core/services/request_handler_service.dart';
import 'package:food_delivery_client/feature/auth/data/datasource/auth_datasource.dart';
import 'package:food_delivery_client/feature/auth/data/models/response/login_response.dart';
import 'package:food_delivery_client/food_delivery_client.dart';

import '../../domain/repository/auth_repository.dart';
import '../../domain/usecases/register_usecase.dart';
import '../../domain/usecases/reset_password_usecase.dart';
import '../../domain/usecases/verify_otp_code_login_usecase.dart';
import '../../domain/usecases/verify_phone_login_usecase.dart';


@LazySingleton(as: AuthRepository)
class AuthRepositoryImpl implements AuthRepository {
  final RequestHandlerService _requestHandlerService;
  final AuthDatasource _authDatasource;

  AuthRepositoryImpl(this._requestHandlerService, this._authDatasource);

  @override
  Future<Either<Failure, LoginResponseModel>> login({
    required String phoneNumber,
    required String password,
  }) async {
    return _requestHandlerService.handleRequestInRepository(
      onRequest: () async {
        return _authDatasource.login(
          phoneNumber: phoneNumber,
          password: password,
        );
      },
    );
  }

  @override
  Future<Either<Failure, SuccessModel>> register({
    required RegisterParams params,
  }) async {
    return _requestHandlerService.handleRequestInRepository(
      onRequest: () async => _authDatasource.register(params: params),
    );
  }

  @override
  Future<Either<Failure, SuccessModel>> resetPassword({
    required ResetPasswordParams params,
  }) async {
    return _requestHandlerService.handleRequestInRepository(
      onRequest: () => _authDatasource.resetPassword(params: params),
    );
  }

  @override
  Future<Either<Failure, SuccessModel>> verifyOtpCodeRegister({
    required VerifyOtpCodeParams params,
  }) async {
    return _requestHandlerService.handleRequestInRepository(
      onRequest: () => _authDatasource.verifyOtpCodeRegister(params: params),
    );
  }

  @override
  Future<Either<Failure, SuccessModel>> verifyOtpCodeResetPassword({
    required VerifyOtpCodeParams params,
  }) async {
    return _requestHandlerService.handleRequestInRepository(
      onRequest: () =>
          _authDatasource.verifyOtpCodeResetPassword(params: params),
    );
  }

  @override
  Future<Either<Failure, SuccessModel>> verifyPhoneRegister({
    required VerifyPhoneNumberParams params,
  }) async {
    return _requestHandlerService.handleRequestInRepository(
      onRequest: () => _authDatasource.verifyPhoneRegister(params: params),
    );
  }

  @override
  Future<Either<Failure, SuccessModel>> verifyPhoneResetPassword({
    required VerifyPhoneNumberParams params,
  }) async {
    return _requestHandlerService.handleRequestInRepository(
      onRequest: () => _authDatasource.verifyPhoneResetPassword(params: params),
    );
  }
}