/* Copyright (C) 2024-2025 LibreWeddingPlanner contributors*/

import { Entity } from "./definitions";
import { Guest } from "./guest";

export class Invitation implements Entity {
  id?: string;
  guests: Array<Guest>;

  constructor(id?: string, guests: Array<Guest> = []) {
    this.id = id;
    this.guests = guests;
  }
}

export class InvitationSerializer {
  fromJson(data: any): Invitation {
    return new Invitation(data.id, (data.guests || []).map((guest: any) => new Guest(guest.id, guest.name, guest.color, guest.status, guest.children)));
  }

  toJson(invitation: Invitation): string {
    return JSON.stringify({ invitation: { guest_ids: invitation.guests.map(guest => guest.id) } });
  }

  apiPath(): string {
    return 'invitations';
  }
}