import 'package:dartz/dartz.dart';
import 'package:equatable/equatable.dart';
import 'package:tugas_akhir_supabase/core/errors/failures.dart';
import 'package:tugas_akhir_supabase/domain/entities/crop_schedule.dart';
import 'package:tugas_akhir_supabase/domain/repositories/crop_schedule_repository.dart';

class GetSchedules {
  final CropScheduleRepository repository;

  GetSchedules(this.repository);

  Future<Either<Failure, List<CropSchedule>>> call(String userId) async {
    return await repository.getSchedules(userId);
  }
}

class GetActiveSchedule {
  final CropScheduleRepository repository;

  GetActiveSchedule(this.repository);

  Future<Either<Failure, Map<String, dynamic>?>> call(String userId) async {
    return await repository.getActiveSchedule(userId);
  }
}

class CreateSchedule {
  final CropScheduleRepository repository;

  CreateSchedule(this.repository);

  Future<Either<Failure, CropSchedule>> call(CreateScheduleParams params) async {
    return await repository.createSchedule(params.userId, params.schedule);
  }
}

class CreateScheduleParams extends Equatable {
  final String userId;
  final CropSchedule schedule;

  const CreateScheduleParams({
    required this.userId,
    required this.schedule,
  });

  @override
  List<Object?> get props => [userId, schedule];
}

class UpdateSchedule {
  final CropScheduleRepository repository;

  UpdateSchedule(this.repository);

  Future<Either<Failure, CropSchedule>> call(UpdateScheduleParams params) async {
    return await repository.updateSchedule(params.userId, params.schedule);
  }
}

class UpdateScheduleParams extends Equatable {
  final String userId;
  final CropSchedule schedule;

  const UpdateScheduleParams({
    required this.userId,
    required this.schedule,
  });

  @override
  List<Object?> get props => [userId, schedule];
}

class DeleteSchedule {
  final CropScheduleRepository repository;

  DeleteSchedule(this.repository);

  Future<Either<Failure, bool>> call(DeleteScheduleParams params) async {
    return await repository.deleteSchedule(params.userId, params.scheduleId);
  }
}

class DeleteScheduleParams extends Equatable {
  final String userId;
  final String scheduleId;

  const DeleteScheduleParams({
    required this.userId,
    required this.scheduleId,
  });

  @override
  List<Object?> get props => [userId, scheduleId];
} 