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';

abstract class AuthRepository {
  Future<Either<Failure, LoginResponseModel>> login({
    required String phoneNumber,
    required String password,
  });
}

@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,
        );
      },
    );
  }
}
