/**
 * Founder Bio Model
 * Manages founder/executive bios for the PR Content Engine
 */

import mongoose, { Schema, Document } from 'mongoose';

// ============================================
// TYPE DEFINITIONS
// ============================================

export type BioType = string;

export type ContentTone = 'professional' | 'educational' | 'authoritative' | 'conversational';
export type ContentWordCount = 100 | 250 | 500 | 800 | 1000 | 1500;

export interface IFounderBio extends Document {
  companyId: string;
  bioType: BioType;
  personName: string;
  title?: string;
  content: string;
  heroImage?: string;
  tone: ContentTone;
  /** Every predefined tone selected at generation time (superset of `tone`). */
  tones?: string[];
  /** Free-text tone supplied via the "Custom" tone option. */
  customTone?: string;
  language?: string;
  wordCount: ContentWordCount;
  status: 'draft' | 'generated' | 'reviewed' | 'published';
  tags?: string[];
  version?: number;
  createdAt: Date;
  updatedAt: Date;
}

// ============================================
// MAIN SCHEMA
// ============================================

const FounderBioSchema = new Schema<IFounderBio>({
  companyId: {
    type: String,
    required: [true, 'Company ID is required'],
    index: true
  },
  bioType: {
    type: String,
    default: 'founder-bio'
  },
  personName: {
    type: String,
    required: [true, 'Person name is required'],
    trim: true,
    maxlength: [200, 'Person name cannot exceed 200 characters']
  },
  title: { type: String, trim: true },
  content: { type: String, default: '' },
  heroImage: { type: String, trim: true },
  tone: {
    type: String,
    enum: ['professional', 'educational', 'authoritative', 'conversational'],
    default: 'professional'
  },
  // Multi-tone selection. `tone` above stays the single enum value for
  // backwards compatibility; these carry the full selection.
  tones: { type: [String], default: undefined },
  customTone: { type: String, trim: true },

  language: { type: String, default: 'en' },
  wordCount: {
    type: Number,
    default: 500
  },
  status: {
    type: String,
    enum: ['draft', 'generated', 'reviewed', 'published'],
    default: 'draft'
  },
  tags: [{ type: String, trim: true }],
  version: { type: Number, default: 1 },
}, {
  timestamps: true
});

// ============================================
// INDEXES
// ============================================

FounderBioSchema.index({ companyId: 1, status: 1 });
FounderBioSchema.index({ companyId: 1, bioType: 1 });

// ============================================
// EXPORT
// ============================================

export const FounderBio = mongoose.model<IFounderBio>('FounderBio', FounderBioSchema);