import 'package:injectable/injectable.dart';
import 'package:krow/features/profile/certificates/data/certificates_api_provider.dart';
import 'package:krow/features/profile/certificates/domain/certificates_repository.dart';
import 'package:krow/features/profile/certificates/data/models/certificate_model.dart';
import 'package:krow/features/profile/certificates/data/models/staff_certificate.dart';

@Injectable(as: CertificatesRepository)
class CertificatesRepositoryImpl extends CertificatesRepository {
  final CertificatesApiProvider _certificatesApiProvider;

  CertificatesRepositoryImpl(this._certificatesApiProvider);

  @override
  Future<List<CertificateModel>> getCertificates() async {
    return _certificatesApiProvider.fetchCertificates();
  }

  @override
  Future<StaffCertificate> putStaffCertificate(
      String certificateId, String imagePath, String certificateDate) {
    return _certificatesApiProvider.putStaffCertificate(
        certificateId, imagePath, certificateDate);
  }

  @override
  Future<List<StaffCertificate>> getStaffCertificates() async{
    return (await _certificatesApiProvider.fetchStaffCertificates()).edges.map((e) => e.node).toList();
  }

  @override
  Future<void> deleteStaffCertificate(String certificateId) {
    return _certificatesApiProvider.deleteStaffCertificate(certificateId);
  }
}
