/**
 * Shared Type Definitions for Creative Studio
 */

// Common Types
export type ImportanceLevel = 'high' | 'medium' | 'low'
export type SeverityLevel = 'low' | 'medium' | 'high'
export type RelationType = 'friend' | 'enemy' | 'family' | 'romantic' | 'mentor' | 'rival' | 'ally' | 'neutral'
export type ThreadStatus = 'pending' | 'in_progress' | 'resolved'
export type ReviewPreset = 'draft' | 'standard' | 'strict' | 'custom'

// API Response Types
export interface ApiResponse<T> {
  data: T
  message?: string
  success?: boolean
}

export interface ApiError {
  detail: string
  status?: number
}

// Memory System Types
export interface TimelineEvent {
  id: string
  episodeNumber: number
  timestamp: string
  characters: string[]
  description: string
  importance: ImportanceLevel
  category: string
  createdAt: string
}

export interface PendingThread {
  id: string
  description: string
  importance: ImportanceLevel
  status: ThreadStatus
  reminderEpisode?: number
  relatedCharacters?: string[]
  createdAt: string
  resolvedAt?: string
}

export interface CharacterState {
  characterName: string
  currentState: string
  history: StateHistoryEntry[]
}

export interface StateHistoryEntry {
  episodeNumber: number
  state: string
  timestamp: string
}

export interface Foreshadowing {
  id: string
  description: string
  importance: ImportanceLevel
  payoffEventId?: string
  payoffEpisode?: number
  status: 'planted' | 'partially_paid' | 'paid_off'
  plantedEpisode: number
  createdAt: string
}

export interface Relationship {
  sourceCharacter: string
  targetCharacter: string
  relationType: RelationType
  strength: number
  description?: string
  evolutionHistory: RelationshipEvolution[]
}

export interface RelationshipEvolution {
  episodeNumber: number
  relationType: RelationType
  strength: number
  description?: string
}

export interface MemoryStatistics {
  totalEvents: number
  totalThreads: number
  resolvedThreads: number
  totalCharacters: number
  totalForeshadowing: number
  paidOffForeshadowing: number
  totalRelationships: number
}

// Review System Types
export interface DimensionConfig {
  name: string
  enabled: boolean
  strictness: number
  weight: number
}

export interface ReviewRule {
  id: string
  name: string
  description: string
  triggerCondition: string
  severity: SeverityLevel
  category: string
  isActive: boolean
}

export interface ReviewConfiguration {
  preset: ReviewPreset
  dimensions: {
    character_consistency: DimensionConfig
    plot_coherence: DimensionConfig
    dialogue_quality: DimensionConfig
    pacing: DimensionConfig
    emotional_depth: DimensionConfig
    thematic_strength: DimensionConfig
  }
  customRules: ReviewRule[]
  createdAt: string
  updatedAt: string
}

export interface Issue {
  id: string
  type: string
  dimension: string
  severity: SeverityLevel
  location: {
    episodeNumber?: number
    lineNumber?: number
    section?: string
  }
  originalText: string
  description: string
  suggestion?: string
  canAutoFix: boolean
  ignored: boolean
}

export interface DimensionScore {
  dimension: string
  score: number
  weight: number
  issues: Issue[]
}

export interface ReviewResult {
  projectId: string
  episodeNumber?: number
  overallScore: number
  dimensionScores: DimensionScore[]
  issues: Issue[]
  summary: string
  reviewedAt: string
  configuration: ReviewConfiguration
}

// Store State Types
export interface LoadingState {
  loading: boolean
  error: string | null
}

// Utility Types
export type Optional<T> = T | null | undefined
export type DeepPartial<T> = {
  [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]
}

// Filter Types
export interface TimelineFilters {
  character?: string
  episode?: number
  importance?: ImportanceLevel
}

export interface IssueFilters {
  severity?: SeverityLevel
  dimension?: string
  ignored?: boolean
}
