import mongoose, { Schema, models, model } from "mongoose";

export interface ConventionDoc {
  _id: string;
  name: string;
  location: string;
  startDate: Date;
  endDate: Date;
  infoUrl: string;
  // Ob Rakku für diese Convention noch Slot-Anfragen annimmt — steuert, ob
  // die öffentliche Seite einen "Slot anfragen"- oder einen "Warteliste"-Weg
  // anbietet (siehe WaitlistEntry).
  slotsAvailable: boolean;
  notes: string;
  notesEn: string;
  // Öffentlicher URL-Pfad (/uploads/conventions/…) eines im Admin
  // hochgeladenen Fotos — wird auf der öffentlichen Übersicht als
  // Hintergrund der "nächste Convention"-Karte gezeigt. Leer = Standardbild.
  image: string;
  // Optionales Convention-Logo (oft breit/länglich, mit Transparenz) — wird
  // über der freien Fläche der Foto-Karte eingeblendet. Nicht beschnitten,
  // Seitenverhältnis bleibt erhalten. Leer = kein Logo.
  logo: string;
  visible: boolean;
  // Wer vom Team vor Ort ist — Selbst-Anmeldung (wie beim Auftrags-
  // Übernehmen), sichtbar fürs ganze Team. Rein intern, nicht Teil der
  // öffentlichen Convention-Übersicht.
  assignedStaffIds: mongoose.Types.ObjectId[];
  createdAt: Date;
  updatedAt: Date;
}

const conventionSchema = new Schema<ConventionDoc>(
  {
    name: { type: String, required: true, trim: true, maxlength: 150 },
    location: { type: String, default: "", trim: true, maxlength: 150 },
    startDate: { type: Date, required: true },
    endDate: { type: Date, required: true },
    infoUrl: { type: String, default: "", trim: true, maxlength: 300 },
    slotsAvailable: { type: Boolean, default: true },
    notes: { type: String, default: "", trim: true, maxlength: 500 },
    notesEn: { type: String, default: "", trim: true, maxlength: 500 },
    image: { type: String, default: "", trim: true, maxlength: 300 },
    logo: { type: String, default: "", trim: true, maxlength: 300 },
    visible: { type: Boolean, default: true },
    assignedStaffIds: { type: [Schema.Types.ObjectId], ref: "Client", default: [] },
  },
  { timestamps: true }
);

export const Convention =
  (models.Convention as mongoose.Model<ConventionDoc>) || model<ConventionDoc>("Convention", conventionSchema);
