import 'package:injectable/injectable.dart';
import 'package:krow/features/profile/benefits/domain/benefits_repository.dart';
import 'package:krow/features/profile/benefits/domain/entities/benefit_entity.dart';
import 'package:krow/features/profile/benefits/domain/entities/benefit_record_entity.dart';

@Injectable(as: BenefitsRepository)
class BenefitsRepositoryImpl implements BenefitsRepository {
  static final _benefitsMock = [
    BenefitEntity(
      name: 'Sick Leave',
      requirement: 'You need at least 8 hours to request sick leave',
      requiredHours: 40,
      currentHours: 10,
      isClaimed: false,
      info: 'Listed certificates are mandatory for employees. If the employee '
          'does not have the complete certificates, they can’t proceed with '
          'their registration.',
      history: [
        BenefitRecordEntity(
          createdAt: DateTime(2024, 6, 14),
          status: RecordStatus.submitted,
        ),
        BenefitRecordEntity(
          createdAt: DateTime(2023, 6, 5),
          status: RecordStatus.submitted,
        ),
        BenefitRecordEntity(
          createdAt: DateTime(2019, 6, 4),
          status: RecordStatus.submitted,
        ),
        BenefitRecordEntity(
          createdAt: DateTime(2018, 6, 1),
          status: RecordStatus.submitted,
        ),
        BenefitRecordEntity(
          createdAt: DateTime(2017, 6, 24),
          status: RecordStatus.submitted,
        ),
        BenefitRecordEntity(
          createdAt: DateTime(2016, 6, 15),
          status: RecordStatus.submitted,
        ),
        BenefitRecordEntity(
          createdAt: DateTime(2015, 6, 6),
          status: RecordStatus.submitted,
        ),
      ],
    ),
    const BenefitEntity(
      name: 'Vacation',
      requirement: 'You need 40 hours to claim vacation pay',
      requiredHours: 40,
      currentHours: 40,
      isClaimed: false,
      info: 'Listed certificates are mandatory for employees. If the employee '
          'does not have the complete certificates, they can’t proceed with '
          'their registration.',
      history: [],
    ),
    const BenefitEntity(
      name: 'Holidays',
      requirement: 'Pay holidays: Thanksgiving, Christmas, New Year',
      requiredHours: 24,
      currentHours: 1,
      isClaimed: false,
      info: 'Listed certificates are mandatory for employees. If the employee '
          'does not have the complete certificates, they can’t proceed with '
          'their registration.',
      history: [],
    ),
  ];

  @override
  Future<List<BenefitEntity>> getStaffBenefits() async {
    await Future.delayed(const Duration(milliseconds: 500));

    return _benefitsMock;
  }

  @override
  Future<BenefitEntity?> requestBenefit({
    required BenefitEntity benefit,
  }) async {
    if (benefit.currentHours != benefit.requiredHours || benefit.isClaimed) {
      return null;
    }

    await Future.delayed(const Duration(seconds: 1));

    return benefit.copyWith(isClaimed: true);
  }
}
