import 'package:cargocalculaterapp/core/error/failure.dart';
import 'package:cargocalculaterapp/features/calculator/data/model/calculate_price_response.dart';
import 'package:cargocalculaterapp/features/calculator/data/model/lead_create_response.dart';
import 'package:cargocalculaterapp/features/calculator/data/model/lead_create_request.dart';
import 'package:cargocalculaterapp/features/calculator/data/model/price_calculate_request.dart';
import 'package:cargocalculaterapp/features/calculator/domain/repository/calculator_repository.dart';
import 'package:dartz/dartz.dart';

import '../data_source/calculator_remote_data_source.dart';

class CalculatorRepositoryImpl extends CalculatorRepository {
  final CalculatorRemoteDataSource calculatorRemoteDataSource;

  CalculatorRepositoryImpl(this.calculatorRemoteDataSource);

  @override
  Future<Either<Failure, CalculatePriceResponse>> calculatePrice(
    PriceCalculateRequest request,
  ) async {
    try {
      final response = await calculatorRemoteDataSource.priceCalculate(request);
      return Right(response);
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }

  @override
  Future<Either<Failure, LeadCreateResponse>> createLead(LeadCreateRequest request) async {
    try {
      final response = await calculatorRemoteDataSource.createLead(request);
      return Right(response);
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }
}
