"""
Strategy Contracts v1 — Types.

انواع داده عمومی ماژول Strategy.
سایر ماژول‌ها فقط از این فایل import می‌کنند.
"""

from dataclasses import dataclass, field
from datetime import date, datetime
from decimal import Decimal
from typing import Optional, List
from uuid import UUID


# ─── Vision ──────────────────────────────────────

@dataclass(frozen=True)
class VisionDTO:
    id: UUID
    tenant_id: UUID
    title: str
    description: str = ""
    status: str = "draft"
    time_horizon_start: Optional[date] = None
    time_horizon_end: Optional[date] = None
    owner_id: Optional[UUID] = None


# ─── Strategic Theme ─────────────────────────────

@dataclass(frozen=True)
class StrategicThemeDTO:
    id: UUID
    tenant_id: UUID
    vision_id: UUID
    name: str
    description: str = ""
    priority: str = "medium"
    status: str = "draft"
    weight: Optional[Decimal] = None


# ─── Objective ───────────────────────────────────

@dataclass(frozen=True)
class ObjectiveDTO:
    id: UUID
    tenant_id: UUID
    title: str
    description: str = ""
    level: str = "strategic"
    status: str = "draft"
    theme_id: Optional[UUID] = None
    parent_id: Optional[UUID] = None
    progress: Optional[Decimal] = None


# ─── Key Result ──────────────────────────────────

@dataclass(frozen=True)
class KeyResultDTO:
    id: UUID
    tenant_id: UUID
    objective_id: UUID
    title: str
    metric_type: str = "number"
    start_value: Optional[Decimal] = None
    target_value: Optional[Decimal] = None
    current_value: Optional[Decimal] = None
    progress: Optional[Decimal] = None


# ─── KPI ─────────────────────────────────────────

@dataclass(frozen=True)
class KPIDefinitionDTO:
    id: UUID
    tenant_id: UUID
    name: str
    code: str
    unit: str = ""
    direction: str = "higher_better"
    frequency: str = "monthly"
    status: str = "draft"


@dataclass(frozen=True)
class KPITargetDTO:
    id: UUID
    kpi_id: UUID
    period: str
    target_value: Decimal
    min_threshold: Optional[Decimal] = None
    max_threshold: Optional[Decimal] = None


@dataclass(frozen=True)
class KPIActualDTO:
    id: UUID
    kpi_id: UUID
    period: str
    actual_value: Decimal
    recorded_at: Optional[datetime] = None


@dataclass(frozen=True)
class KPIAssignmentDTO:
    id: UUID
    kpi_id: UUID
    level: str
    entity_id: Optional[UUID] = None


# ─── Strategy Map ────────────────────────────────

@dataclass(frozen=True)
class StrategyMapDTO:
    id: UUID
    tenant_id: UUID
    name: str
    description: str = ""
    status: str = "draft"
    vision_id: Optional[UUID] = None


@dataclass(frozen=True)
class CausalLinkDTO:
    id: UUID
    map_id: UUID
    source_objective_id: UUID
    target_objective_id: UUID
    strength: str = "medium"


# ─── Scorecard ───────────────────────────────────

@dataclass(frozen=True)
class ScorecardDTO:
    id: UUID
    tenant_id: UUID
    name: str
    status: str = "draft"
    map_id: Optional[UUID] = None
    period_start: Optional[date] = None
    period_end: Optional[date] = None


@dataclass(frozen=True)
class ScorecardMeasureDTO:
    id: UUID
    perspective_id: UUID
    name: str
    kpi_id: Optional[UUID] = None
    target_value: Optional[Decimal] = None
    actual_value: Optional[Decimal] = None
    weight: Optional[Decimal] = None


# ─── Stage-Gate ──────────────────────────────────

@dataclass(frozen=True)
class GateProcessDTO:
    id: UUID
    tenant_id: UUID
    name: str
    description: str = ""
    applicable_to: str = ""


@dataclass(frozen=True)
class GateDTO:
    id: UUID
    process_id: UUID
    name: str
    sequence: int = 0


@dataclass(frozen=True)
class GateReviewDTO:
    id: UUID
    gate_id: UUID
    entity_id: Optional[UUID] = None
    status: str = "pending"
    decision: str = ""


# ─── Policy ──────────────────────────────────────

@dataclass(frozen=True)
class PolicyDTO:
    id: UUID
    tenant_id: UUID
    title: str
    code: str = ""
    category: str = ""
    version: int = 1
    status: str = "draft"
    effective_date: Optional[date] = None
    review_date: Optional[date] = None
    owner_id: Optional[UUID] = None
    approver_id: Optional[UUID] = None
    document_id: Optional[UUID] = None


@dataclass(frozen=True)
class PolicyAcknowledgmentDTO:
    id: UUID
    policy_id: UUID
    user_id: UUID
    acknowledged_at: Optional[datetime] = None
