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

import { Serializable } from "../api/abstract-api";
import { Entity } from "./definitions";
import { Group } from "./group";

export const guestStatuses = ['considered', 'invited', 'confirmed', 'declined', 'tentative'] as const;
export type GuestStatus = typeof guestStatuses[number];

export class Guest implements Entity {
  id?: string;
  name?: string;
  color?: string;
  status?: GuestStatus;
  children?: Guest[];
  group?: Group;

  constructor(id?: string, name?: string, color?: string, status?: GuestStatus, children?: Guest[], Group?: Group) {
    this.id = id;
    this.name = name;
    this.color = color;
    this.status = status;
    this.children = children;
    this.group = Group;
  }
}

export class GuestSerializer implements Serializable<Guest> {
  fromJson(data: any): Guest {
    return new Guest(data.id, data.name, data.color, data.status, data.children, new Group(data.group?.id, data.group?.name));
  }

  toJson(guest: Guest): string {
    return JSON.stringify({ guest: { name: guest.name, status: guest.status, group_id: guest.group?.id } });
  }

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

