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


class RecipientService {
  static const String _objectType = Services.recipients;

  static final BasicService<Recipient> _basicService = BasicService<Recipient>(
    objectType: _objectType,
    fromJson: (json) => RecipientResponse.fromJson(json).recipients.map((dto) => dto.toDomain()).toList(),
  );

  static BasicService<Recipient> get basicService => _basicService;

  static Future<List<Recipient>> list(String organizationRef, String _) async {
    return _basicService.list(organizationRef, organizationRef);
  }

  static Future<Recipient> get(String recipientRef) async {
    return _basicService.get(recipientRef);
  }

  static Future<List<Recipient>> create(String organizationRef, Recipient recipient) async {
    return _basicService.create(organizationRef, recipient.toDTO().toJson());
  }

  static Future<List<Recipient>> update(Recipient recipient) async {
    return _basicService.update(recipient.toDTO().toJson());
  }

  static Future<List<Recipient>> delete(Recipient recipient) async {
    return _basicService.delete(recipient.storable.id);
  }
}
