/**
 * Template Style Model
 *
 * Super-Admin-managed "marketing style" templates (e.g. Russell Brunson,
 * Alex Hormozi, Neil Patel …). Each template captures a marketing STRATEGY
 * ONLY — conversion framework, page flow, content structure, messaging
 * approach, and CTA strategy — that the Landing Page builder can apply.
 *
 * Templates deliberately carry NO visual styling (colours, fonts, buttons,
 * radii, animation). All branding and visual design comes from the company's
 * own brand assets and visual identity.
 *
 * Templates are global (not company-scoped). Only enabled templates are exposed
 * to the Landing Page builder.
 */

import mongoose, { Schema, Document } from 'mongoose';

export type TemplateLayoutType =
  | 'Funnel'
  | 'Minimal'
  | 'Corporate'
  | 'Storytelling'
  | 'Bold'
  | 'Editorial'
  | 'Long-Form Sales'
  | 'Other';

export interface ITemplateStyle extends Document {
  name: string;
  slug: string;
  description: string;
  // Single prompt holding all instructions, flow, structure, and generation
  // logic — applied directly to Landing Page generation.
  prompt: string;
  // Strategy-only fields (no visual styling — visuals come from brand assets)
  layoutType: TemplateLayoutType | string;   // page structure / layout archetype
  conversionFramework: string;                // e.g. Hook → Story → Offer
  pageFlow: string;                           // recommended section order / content structure
  copywritingTone: string;                    // messaging approach & tone
  heroSectionStyle: string;                   // hero content strategy (what it must communicate)
  ctaStyle: string;                           // CTA strategy
  enabled: boolean;
  displayOrder: number;
  isDefault: boolean;
  createdById?: string;
  createdAt: Date;
  updatedAt: Date;
}

const TemplateStyleSchema = new Schema<ITemplateStyle>({
  name: { type: String, required: [true, 'Template name is required'], trim: true, maxlength: 120 },
  slug: { type: String, required: true, unique: true, index: true },
  description: { type: String, default: '', trim: true, maxlength: 500 },
  // Single prompt — all instructions, flow, structure, and generation logic.
  prompt: { type: String, default: '' },
  // Strategy-only fields — templates define marketing strategy, never visual design.
  layoutType: { type: String, default: 'Other' },
  conversionFramework: { type: String, default: '' },
  pageFlow: { type: String, default: '' },
  copywritingTone: { type: String, default: '' },
  heroSectionStyle: { type: String, default: '' },
  ctaStyle: { type: String, default: '' },
  // enable/disable — only enabled templates reach the Landing Page builder
  enabled: { type: Boolean, default: true, index: true },
  displayOrder: { type: Number, default: 0 },
  isDefault: { type: Boolean, default: false },
  createdById: { type: String },
}, {
  timestamps: true,
});

TemplateStyleSchema.index({ enabled: 1, displayOrder: 1 });

export const TemplateStyle =
  mongoose.models.TemplateStyle ||
  mongoose.model<ITemplateStyle>('TemplateStyle', TemplateStyleSchema);
