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

// Kuratierte Liste von Instagram-Beitrags-Links fürs Startseiten-"Feed"
// (siehe components/InstagramFeed.tsx) — Instagrams eigene Embed-API
// (oEmbed) verlangt inzwischen einen Meta-App-Zugangsschlüssel, den nur Till
// selbst über sein eigenes Instagram/Facebook-Business-Konto einrichten
// kann. Das offizielle Einzelpost-Embed-Skript (instagram.com/embed.js)
// funktioniert dagegen ohne API-Zugang — reicht für eine handkuratierte,
// echte Instagram-Einbettung ohne Extra-Vertrag/-Kosten.
export interface InstagramPostDoc {
  _id: string;
  url: string;
  visible: boolean;
  sortOrder: number;
  createdAt: Date;
}

const instagramPostSchema = new Schema<InstagramPostDoc>(
  {
    url: { type: String, required: true, trim: true, maxlength: 300 },
    visible: { type: Boolean, default: true },
    sortOrder: { type: Number, default: 0 },
  },
  { timestamps: { createdAt: true, updatedAt: false } }
);

export const InstagramPost =
  (models.InstagramPost as mongoose.Model<InstagramPostDoc>) ||
  model<InstagramPostDoc>("InstagramPost", instagramPostSchema);
