import 'package:cargocalculaterapp/core/error/failure.dart';
import 'package:cargocalculaterapp/features/home/data/models/banner_response.dart';
import 'package:cargocalculaterapp/features/home/data/models/comment_request.dart';
import 'package:cargocalculaterapp/features/home/data/models/comment_response.dart';
import 'package:cargocalculaterapp/features/home/data/models/notification_response.dart';
import 'package:cargocalculaterapp/features/home/data/models/order_single_response.dart';
import 'package:cargocalculaterapp/features/home/data/models/orders_list_response.dart';
import 'package:cargocalculaterapp/features/home/data/models/read_notification_request.dart';
import 'package:cargocalculaterapp/features/home/data/models/read_notification_response.dart';
import 'package:dartz/dartz.dart';
import '../../domain/repository/home_repository.dart';
import '../data_source/remote/home_remote_data_source.dart';

class HomeRepositoryImpl extends HomeRepository {
  final HomeRemoteDataSource remoteDataSource;

  HomeRepositoryImpl(this.remoteDataSource);

  @override
  Future<Either<Failure, OrdersListResponse>> ordersList(
    Map<String, dynamic> request,
  ) async {
    try {
      final response = await remoteDataSource.ordersList(request);
      return Right(response);
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }

  @override
  Future<Either<Failure, OrderSingleResponse>> orderSingle(
    String orderId,
  ) async {
    try {
      final response = await remoteDataSource.orderSingle(orderId);
      return Right(response);
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }

  @override
  Future<Either<Failure, CommentResponse>> comment(
    CommentRequest request,
  ) async {
    try {
      final response = await remoteDataSource.comment(request);
      return Right(response);
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }

  @override
  Future<Either<Failure, NotificationResponse>> notification(
    Map<String, dynamic> request,
  ) async {
    try {
      final response = await remoteDataSource.notification(request);
      return Right(response);
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }

  @override
  Future<Either<Failure, ReadNotificationResponse>> notificationRead(
    ReadNotificationRequest request,
  ) async {
    try {
      final response = await remoteDataSource.notificationRead(request);
      return Right(response);
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }

  @override
  Future<Either<Failure, List<BannerResponse>>> bannersGet() async {
    try {
      final response = await remoteDataSource.bannersResponse();
      return Right(response);
    } catch (e) {
      return Left(ServerFailure(message: e.toString()));
    }
  }
}
