import 'package:food_delivery_client/core/services/request_handler_service.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 AuthDatasource {
  Future<LoginResponseModel> login({
    required String phoneNumber,
    required String password,
  });
}

@LazySingleton(as: AuthDatasource)
class AuthDatasourceImpl implements AuthDatasource {
  final RequestHandlerService _requestHandlerService;

  AuthDatasourceImpl(this._requestHandlerService);

  @override
  Future<LoginResponseModel> login({
    required String phoneNumber,
    required String password,
  }) async {
    return _requestHandlerService.handleRequest(
      path: ApiConst.login,
      method: RequestMethodEnum.post,
      data: {"password": password, "phoneNumber": phoneNumber},
      fromJson: (response) async => LoginResponseModel.fromJson(response.data),
    );
  }
}
