/**
 * Décrit, pour chaque modèle, les champs à afficher/éditer dans
 * l'interface d'administration maison (src/admin/router.js).
 * Un seul moteur générique (liste + formulaire) lit cette config pour
 * les 15 ressources, plutôt qu'un écran codé à la main pour chacune.
 *
 * Types de champ supportés : text, textarea, boolean, number, datetime,
 * select (avec `options`), image (upload), belongsTo (liste déroulante
 * alimentée par un autre modèle).
 * `translated: true` génère automatiquement les deux colonnes `_fr`/`_en`.
 */
const {
  Category, Page, Article, Event, Document, ContactMessage,
  Stat, Partner, Person, ImportantLink, GalleryImage, HeroSlide, Testimonial, FAQ,
  KnowledgeItem,
} = require("../models");

const resources = {
  categories: {
    label: "Catégories", model: Category, group: "Contenu",
    fields: [
      { name: "name", label: "Nom", type: "text", translated: true, required: true },
      { name: "slug", label: "Slug", type: "text" },
    ],
    listColumns: ["name_fr", "slug"],
  },
  pages: {
    label: "Pages", model: Page, group: "Contenu",
    fields: [
      { name: "title", label: "Titre", type: "text", translated: true, required: true },
      { name: "slug", label: "Slug", type: "text", required: true },
      { name: "body", label: "Contenu", type: "textarea", translated: true, required: true },
      { name: "order", label: "Ordre", type: "number" },
      { name: "is_published", label: "Publié", type: "boolean" },
    ],
    listColumns: ["title_fr", "slug", "is_published", "order"],
  },
  articles: {
    label: "Actualités", model: Article, group: "Contenu", uploadField: "cover_image",
    fields: [
      { name: "title", label: "Titre", type: "text", translated: true, required: true },
      { name: "slug", label: "Slug", type: "text", required: true },
      { name: "excerpt", label: "Extrait", type: "textarea", translated: true },
      { name: "body", label: "Contenu", type: "textarea", translated: true, required: true },
      { name: "cover_image", label: "Image de couverture", type: "image" },
      { name: "category_id", label: "Catégorie", type: "belongsTo", refModel: Category, refLabel: "name_fr" },
      { name: "is_featured", label: "Mis en avant (accueil)", type: "boolean" },
      { name: "is_published", label: "Publié", type: "boolean" },
      { name: "published_at", label: "Date de publication", type: "datetime" },
    ],
    listColumns: ["title_fr", "is_featured", "is_published", "published_at"],
  },
  events: {
    label: "Événements", model: Event, group: "Contenu", uploadField: "cover_image",
    fields: [
      { name: "title", label: "Titre", type: "text", translated: true, required: true },
      { name: "slug", label: "Slug", type: "text", required: true },
      { name: "description", label: "Description", type: "textarea", translated: true, required: true },
      { name: "location", label: "Lieu", type: "text", translated: true },
      { name: "theme", label: "Thème", type: "text", translated: true },
      { name: "start_date", label: "Date de début", type: "datetime", required: true },
      { name: "end_date", label: "Date de fin", type: "datetime" },
      { name: "registration_url", label: "Lien d'inscription", type: "text" },
      { name: "programme_url", label: "Lien programme/rapport", type: "text" },
      { name: "cover_image", label: "Image de couverture", type: "image" },
      { name: "is_published", label: "Publié", type: "boolean" },
      { name: "manually_closed", label: "Forcer statut terminé", type: "boolean" },
    ],
    listColumns: ["title_fr", "start_date", "manually_closed", "is_published"],
  },
  documents: {
    label: "Documents", model: Document, group: "Contenu", uploadField: "file",
    fields: [
      { name: "title", label: "Titre", type: "text", required: true },
      { name: "description", label: "Description", type: "textarea" },
      { name: "file", label: "Fichier", type: "image" },
      { name: "is_public", label: "Public", type: "boolean" },
      { name: "extracted_text", label: "Texte extrait (indexation chatbot)", type: "textarea" },
    ],
    listColumns: ["title", "is_public", "created_at"],
  },
  faqs: {
    label: "FAQ", model: FAQ, group: "Contenu",
    fields: [
      { name: "question", label: "Question", type: "text", translated: true, required: true },
      { name: "answer", label: "Réponse", type: "textarea", translated: true, required: true },
      { name: "order", label: "Ordre", type: "number" },
    ],
    listColumns: ["question_fr", "order"],
  },
  stats: {
    label: "Chiffres-clés", model: Stat, group: "Page d'accueil",
    fields: [
      { name: "value", label: "Valeur (ex: 8+)", type: "text", required: true },
      { name: "label", label: "Libellé", type: "text", translated: true, required: true },
      { name: "order", label: "Ordre", type: "number" },
    ],
    listColumns: ["value", "label_fr", "order"],
  },
  partners: {
    label: "Partenaires", model: Partner, group: "Page d'accueil", uploadField: "logo",
    fields: [
      { name: "name", label: "Nom", type: "text", required: true },
      { name: "logo", label: "Logo", type: "image", required: true },
      { name: "website_url", label: "Site web", type: "text" },
      { name: "partner_type", label: "Type", type: "select", options: ["sponsor", "institutional"] },
      { name: "order", label: "Ordre", type: "number" },
    ],
    listColumns: ["name", "partner_type", "order"],
  },
  people: {
    label: "Comité & intervenants", model: Person, group: "Contenu", uploadField: "photo",
    fields: [
      { name: "full_name", label: "Nom complet", type: "text", required: true },
      { name: "title", label: "Fonction / organisation", type: "text", translated: true },
      { name: "bio", label: "Bio", type: "textarea", translated: true },
      { name: "photo", label: "Photo", type: "image" },
      { name: "role_type", label: "Rôle", type: "select", options: ["committee", "speaker"] },
      { name: "event_id", label: "Événement (si intervenant)", type: "belongsTo", refModel: Event, refLabel: "title_fr" },
      { name: "linkedin_url", label: "LinkedIn", type: "text" },
      { name: "order", label: "Ordre", type: "number" },
    ],
    listColumns: ["full_name", "role_type", "order"],
  },
  "important-links": {
    label: "Liens institutionnels", model: ImportantLink, group: "Page d'accueil",
    fields: [
      { name: "label", label: "Libellé", type: "text", translated: true, required: true },
      { name: "url", label: "URL", type: "text", required: true },
      { name: "order", label: "Ordre", type: "number" },
    ],
    listColumns: ["label_fr", "url", "order"],
  },
  gallery: {
    label: "Galerie photo", model: GalleryImage, group: "Page d'accueil", uploadField: "image",
    fields: [
      { name: "image", label: "Photo", type: "image", required: true },
      { name: "caption", label: "Légende", type: "text", translated: true },
      { name: "event_id", label: "Événement", type: "belongsTo", refModel: Event, refLabel: "title_fr" },
      { name: "order", label: "Ordre", type: "number" },
    ],
    listColumns: ["caption_fr", "order"],
  },
  "hero-slides": {
    label: "Photos du hero (accueil)", model: HeroSlide, group: "Page d'accueil", uploadField: "image",
    fields: [
      { name: "image", label: "Photo", type: "image", required: true },
      { name: "caption", label: "Légende", type: "text" },
      { name: "order", label: "Ordre", type: "number" },
      { name: "is_published", label: "Publié", type: "boolean" },
    ],
    listColumns: ["caption", "is_published", "order"],
  },
  testimonials: {
    label: "Témoignages", model: Testimonial, group: "Page d'accueil", uploadField: "photo",
    fields: [
      { name: "quote", label: "Témoignage", type: "textarea", translated: true, required: true },
      { name: "author_name", label: "Nom de l'auteur·e", type: "text", required: true },
      { name: "author_role", label: "Fonction de l'auteur·e", type: "text", translated: true },
      { name: "photo", label: "Photo", type: "image" },
      { name: "order", label: "Ordre", type: "number" },
      { name: "is_published", label: "Publié", type: "boolean" },
    ],
    listColumns: ["author_name", "is_published", "order"],
  },
  "contact-messages": {
    label: "Messages de contact", model: ContactMessage, group: "Contenu", readOnly: true,
    fields: [
      { name: "name", label: "Nom", type: "text" },
      { name: "email", label: "E-mail", type: "text" },
      { name: "subject", label: "Objet", type: "text" },
      { name: "message", label: "Message", type: "textarea" },
      { name: "language", label: "Langue", type: "text" },
      { name: "is_read", label: "Lu", type: "boolean" },
    ],
    listColumns: ["name", "email", "subject", "is_read", "created_at"],
  },
  "knowledge-items": {
    label: "Base de connaissances (chatbot)", model: KnowledgeItem, group: "Chatbot",
    fields: [
      { name: "question", label: "Question", type: "text", translated: true, required: true },
      { name: "answer", label: "Réponse", type: "textarea", translated: true, required: true },
      { name: "is_published", label: "Publié", type: "boolean" },
      { name: "order", label: "Ordre", type: "number" },
    ],
    listColumns: ["question_fr", "is_published", "order"],
    reindexable: true,
  },
};

module.exports = resources;
