/**
 * PR Content Repurpose Model
 * Manages repurposed content for the PR Content Studio
 */

import mongoose, { Schema, Document } from 'mongoose';

// ============================================
// TYPE DEFINITIONS
// ============================================

export type RepurposeTargetFormat = 'linkedin-post' | 'twitter-thread' | 'newsletter' | 'blog-article' | 'executive-summary' | 'press-summary';

export interface IPRContentRepurpose extends Document {
  companyId: string;
  sourceId: string;
  sourceType: string;
  targetFormat: RepurposeTargetFormat;
  generatedContent: string;
  headline?: string;
  wordCount?: number;
  tags?: string[];
  createdAt: Date;
  updatedAt: Date;
}

// ============================================
// MAIN SCHEMA
// ============================================

const PRContentRepurposeSchema = new Schema<IPRContentRepurpose>({
  companyId: {
    type: String,
    required: [true, 'Company ID is required'],
    index: true
  },
  sourceId: {
    type: String,
    required: [true, 'Source content ID is required'],
    index: true
  },
  sourceType: {
    type: String,
    required: [true, 'Source content type is required'],
    enum: ['press-release', 'expert-column', 'news-story', 'thought-leadership'],
  },
  targetFormat: {
    type: String,
    enum: ['linkedin-post', 'twitter-thread', 'newsletter', 'blog-article', 'executive-summary', 'press-summary'],
    default: 'linkedin-post'
  },
  generatedContent: {
    type: String,
    required: [true, 'Generated content is required'],
    default: ''
  },
  headline: { type: String, trim: true, default: '' },
  wordCount: { type: Number, default: 0 },
  tags: [{ type: String, trim: true }],
}, {
  timestamps: true
});

// ============================================
// INDEXES
// ============================================

PRContentRepurposeSchema.index({ companyId: 1, sourceId: 1 });
PRContentRepurposeSchema.index({ companyId: 1, targetFormat: 1 });

// ============================================
// EXPORT
// ============================================

export const PRContentRepurpose = mongoose.model<IPRContentRepurpose>('PRContentRepurpose', PRContentRepurposeSchema);