/**
 * Media Mention Model
 * Tracks media coverage and mentions
 */

import mongoose, { Schema, Document } from 'mongoose';

// ============================================
// TYPE DEFINITIONS
// ============================================

export type MentionType =
  | 'article'
  | 'podcast'
  | 'video'
  | 'social-post'
  | 'review'
  | 'press-release'
  | 'interview'
  | 'award';

export type SentimentType = 'positive' | 'neutral' | 'negative';

export interface IMediaMention extends Document {
  companyId: string;
  title: string;
  source: string;
  url?: string;
  mentionType: MentionType;
  sentiment: SentimentType;
  reach?: number;
  impressions?: number;
  summary?: string;
  date: string;
  author?: string;
  notes?: string;
  tags?: string[];
  createdAt: Date;
  updatedAt: Date;
}

// ============================================
// MAIN SCHEMA
// ============================================

const MediaMentionSchema = new Schema<IMediaMention>({
  companyId: {
    type: String,
    required: [true, 'Company ID is required'],
    index: true
  },
  title: {
    type: String,
    required: [true, 'Title is required'],
    trim: true,
    maxlength: [500, 'Title cannot exceed 500 characters']
  },
  source: {
    type: String,
    required: [true, 'Source is required'],
    trim: true,
    maxlength: [200, 'Source cannot exceed 200 characters']
  },
  url: { type: String, trim: true },
  mentionType: {
    type: String,
    enum: ['article', 'podcast', 'video', 'social-post', 'review', 'press-release', 'interview', 'award'],
    required: [true, 'Mention type is required']
  },
  sentiment: {
    type: String,
    enum: ['positive', 'neutral', 'negative'],
    default: 'neutral'
  },
  reach: { type: Number, min: 0 },
  impressions: { type: Number, min: 0 },
  summary: { type: String, trim: true },
  date: {
    type: String,
    required: [true, 'Date is required']
  },
  author: { type: String, trim: true },
  notes: { type: String, trim: true },
  tags: [{ type: String, trim: true }],
}, {
  timestamps: true
});

// ============================================
// INDEXES
// ============================================

MediaMentionSchema.index({ companyId: 1, mentionType: 1 });
MediaMentionSchema.index({ companyId: 1, sentiment: 1 });
MediaMentionSchema.index({ companyId: 1, date: -1 });

// ============================================
// EXPORT
// ============================================

export const MediaMention = mongoose.model<IMediaMention>('MediaMention', MediaMentionSchema);