import 'package:dartz/dartz.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:tugas_akhir_supabase/domain/entities/crop_schedule.dart';
import 'package:tugas_akhir_supabase/domain/repositories/crop_schedule_repository.dart';
import 'package:tugas_akhir_supabase/domain/usecases/get_schedules.dart';

import 'get_schedules_test.mocks.dart';

@GenerateMocks([CropScheduleRepository])
void main() {
  late GetSchedules usecase;
  late MockCropScheduleRepository mockRepository;

  setUp(() {
    mockRepository = MockCropScheduleRepository();
    usecase = GetSchedules(mockRepository);
  });

  final tUserId = 'test-user-id';
  final tSchedules = [
    CropSchedule(
      id: '1',
      cropName: 'Rice',
      startDate: DateTime(2023, 1, 1),
      endDate: DateTime(2023, 4, 1),
      plot: 2,
      fieldId: 'field1',
      color: Colors.green,
    ),
    CropSchedule(
      id: '2',
      cropName: 'Corn',
      startDate: DateTime(2023, 2, 1),
      endDate: DateTime(2023, 5, 1),
      plot: 3,
      fieldId: 'field2',
      color: Colors.yellow,
    ),
  ];

  test(
    'should get list of schedules from the repository',
    () async {
      // arrange
      when(mockRepository.getSchedules(any))
          .thenAnswer((_) async => Right(tSchedules));

      // act
      final result = await usecase(tUserId);

      // assert
      expect(result, Right(tSchedules));
      verify(mockRepository.getSchedules(tUserId));
      verifyNoMoreInteractions(mockRepository);
    },
  );
} 