"""
Report Data Models

Data structures for competitive intelligence reports, briefings, and strategic outputs.
"""

from dataclasses import dataclass, field
from datetime import datetime
from typing import Dict, List, Any, Optional
from enum import Enum


class AlertSeverity(Enum):
    """Severity levels for trend alerts"""
    LOW = "low"
    MEDIUM = "medium"
    HIGH = "high"
    CRITICAL = "critical"


class ReportType(Enum):
    """Types of competitive intelligence reports"""
    DAILY_BRIEFING = "daily_briefing"
    WEEKLY_STRATEGIC = "weekly_strategic"
    MONTHLY_DEEP_DIVE = "monthly_deep_dive"
    TREND_ALERT = "trend_alert"


@dataclass
class RecommendationItem:
    """Individual strategic recommendation"""
    title: str
    description: str
    priority: str  # critical, high, medium, low
    expected_impact: str
    implementation_steps: List[str] = field(default_factory=list)
    timeline: str = "2-4 weeks"
    resources_required: List[str] = field(default_factory=list)
    success_metrics: List[str] = field(default_factory=list)
    
    def to_dict(self) -> Dict[str, Any]:
        return {
            'title': self.title,
            'description': self.description,
            'priority': self.priority,
            'expected_impact': self.expected_impact,
            'implementation_steps': self.implementation_steps,
            'timeline': self.timeline,
            'resources_required': self.resources_required,
            'success_metrics': self.success_metrics
        }


@dataclass
class TrendAlert:
    """Alert about significant competitive trends"""
    alert_type: str
    trend_description: str
    severity: AlertSeverity
    affected_competitors: List[str] = field(default_factory=list)
    impact_assessment: str = ""
    recommended_response: str = ""
    created_at: datetime = field(default_factory=datetime.utcnow)
    
    def to_dict(self) -> Dict[str, Any]:
        return {
            'alert_type': self.alert_type,
            'trend_description': self.trend_description,
            'severity': self.severity.value,
            'affected_competitors': self.affected_competitors,
            'impact_assessment': self.impact_assessment,
            'recommended_response': self.recommended_response,
            'created_at': self.created_at.isoformat()
        }


@dataclass
class CompetitiveBriefing:
    """Daily competitive intelligence briefing"""
    report_date: datetime
    report_type: ReportType = ReportType.DAILY_BRIEFING
    
    # Key competitive intelligence
    critical_gaps: List[Dict[str, Any]] = field(default_factory=list)
    trending_topics: List[Dict[str, Any]] = field(default_factory=list)
    competitor_movements: List[Dict[str, Any]] = field(default_factory=list)
    
    # Quick wins and actions
    quick_wins: List[str] = field(default_factory=list)
    immediate_actions: List[str] = field(default_factory=list)
    
    # Summary and context
    summary: str = ""
    key_metrics: Dict[str, Any] = field(default_factory=dict)
    
    def to_dict(self) -> Dict[str, Any]:
        return {
            'report_date': self.report_date.isoformat(),
            'report_type': self.report_type.value,
            'critical_gaps': self.critical_gaps,
            'trending_topics': self.trending_topics,
            'competitor_movements': self.competitor_movements,
            'quick_wins': self.quick_wins,
            'immediate_actions': self.immediate_actions,
            'summary': self.summary,
            'key_metrics': self.key_metrics
        }


@dataclass
class StrategicReport:
    """Weekly strategic competitive analysis report"""
    report_date: datetime
    report_period: str  # "7d", "30d", etc.
    report_type: ReportType = ReportType.WEEKLY_STRATEGIC
    
    # Strategic analysis
    strategic_recommendations: List[RecommendationItem] = field(default_factory=list)
    performance_analysis: Dict[str, Any] = field(default_factory=dict)
    market_opportunities: List[Dict[str, Any]] = field(default_factory=list)
    
    # Competitive intelligence
    competitor_analysis: List[Dict[str, Any]] = field(default_factory=list)
    market_trends: List[Dict[str, Any]] = field(default_factory=list)
    
    # Executive summary
    executive_summary: str = ""
    key_takeaways: List[str] = field(default_factory=list)
    next_actions: List[str] = field(default_factory=list)
    
    def to_dict(self) -> Dict[str, Any]:
        return {
            'report_date': self.report_date.isoformat(),
            'report_period': self.report_period,
            'report_type': self.report_type.value,
            'strategic_recommendations': [rec.to_dict() for rec in self.strategic_recommendations],
            'performance_analysis': self.performance_analysis,
            'market_opportunities': self.market_opportunities,
            'competitor_analysis': self.competitor_analysis,
            'market_trends': self.market_trends,
            'executive_summary': self.executive_summary,
            'key_takeaways': self.key_takeaways,
            'next_actions': self.next_actions
        }