import 'package:pshared/api/responses/invitations.dart';
import 'package:pshared/data/mapper/invitation/invitation.dart';
import 'package:pshared/models/invitation/invitation.dart';
import 'package:pshared/service/services.dart';
import 'package:pshared/service/template.dart';


class InvitationService {
  static const String _objectType = Services.invitations;

  static final BasicService<Invitation> _basicService = BasicService<Invitation>(
    objectType: _objectType,
    fromJson: (json) => InvitationsResponse.fromJson(json).invitations.map((dto) => dto.toDomain()).toList(),
  );

  static BasicService<Invitation> get basicService => _basicService;

  static Future<List<Invitation>> list(String organizationRef, String parentRef) {
    return _basicService.list(organizationRef, parentRef);
  }

  static Future<List<Invitation>> create(String organizationRef, Invitation invitation) {
    return _basicService.create(organizationRef, invitation.toDTO().toJson());
  }

  static Future<List<Invitation>> update(Invitation invitation) {
    return _basicService.update(invitation.toDTO().toJson());
  }

  static Future<List<Invitation>> delete(Invitation invitation) {
    return _basicService.delete(invitation.id);
  }

  static Future<List<Invitation>> archive({
    required String organizationRef,
    required Invitation invitation,
    required bool archived,
  }) {
    return _basicService.archive(
      organizationRef: organizationRef,
      objectRef: invitation.id,
      newIsArchived: archived,
    );
  }
}
