/**
 * Media Outreach Model
 * Manages journalist pitches, podcast pitches, and speaking outreach for the PR Content Studio
 */

import mongoose, { Schema, Document } from 'mongoose';

// ============================================
// TYPE DEFINITIONS
// ============================================

export type OutreachType = 'journalist-email' | 'publication-pitch' | 'podcast-pitch' | 'speaking-opportunity' | 'event-participation';

export type OutreachStatus = 'draft' | 'generated' | 'reviewed' | 'published';

export interface IMediaOutreach extends Document {
  companyId: string;
  title: string;
  outreachType: OutreachType;
  description?: string;
  recipientName?: string;
  recipientEmail?: string;
  recipientOrganization?: string;
  subjectLine: string;
  body: string;
  callToAction: string;
  heroImage?: string;
  linkedContentId?: string;
  linkedContentType?: string;
  status: OutreachStatus;
  sentDate?: string;
  responseDate?: string;
  notes?: string;
  tags?: string[];
  language?: string;
  createdAt: Date;
  updatedAt: Date;
}

// ============================================
// MAIN SCHEMA
// ============================================

const MediaOutreachSchema = new Schema<IMediaOutreach>({
  companyId: {
    type: String,
    required: [true, 'Company ID is required'],
    index: true
  },
  title: {
    type: String,
    required: [true, 'Title is required'],
    trim: true,
    maxlength: [300, 'Title cannot exceed 300 characters']
  },
  description: {
    type: String,
    trim: true,
    maxlength: [1000, 'Description cannot exceed 1000 characters'],
    default: ''
  },
  outreachType: {
    type: String,
    enum: ['journalist-email', 'publication-pitch', 'podcast-pitch', 'speaking-opportunity', 'event-participation'],
    default: 'journalist-email'
  },
  recipientName: { type: String, trim: true, default: '' },
  recipientEmail: { type: String, trim: true, default: '' },
  recipientOrganization: { type: String, trim: true, default: '' },
  subjectLine: { type: String, trim: true, default: '' },
  body: { type: String, default: '' },
  callToAction: { type: String, default: '' },
  heroImage: { type: String, trim: true },
  linkedContentId: { type: String, default: '' },
  linkedContentType: {
    type: String,
    enum: ['press-release', 'expert-column', 'news-story', 'thought-leadership', ''],
    default: ''
  },
  status: {
    type: String,
    enum: ['draft', 'generated', 'reviewed', 'published'],
    default: 'draft'
  },
  sentDate: { type: String },
  responseDate: { type: String },
  notes: { type: String, default: '' },
  tags: [{ type: String, trim: true }],
  language: { type: String, default: 'en' },
}, {
  timestamps: true
});

// ============================================
// INDEXES
// ============================================

MediaOutreachSchema.index({ companyId: 1, status: 1 });
MediaOutreachSchema.index({ companyId: 1, outreachType: 1 });

// ============================================
// EXPORT
// ============================================

export const MediaOutreach = mongoose.model<IMediaOutreach>('MediaOutreach', MediaOutreachSchema);