from datetime import datetime
from enum import Enum
from typing import List, Optional
from uuid import UUID

from pydantic import Field

from src.models import DefultBase, Pagination

# from src.overhaul_scope.schema import ScopeRead
# from src.scope_equipment_job.schema import ScopeEquipmentJobRead
# from src.job.schema import ActivityMasterRead


class EquipmentBase(DefultBase):
    pass


# class OverhaulScheduleCreate(OverhaulScheduleBase):
#     year: int
#     plan_duration: Optional[int] = Field(None)
#     planned_outage: Optional[int] = Field(None)
#     actual_shutdown: Optional[int] = Field(None)
#     start: datetime
#     finish: datetime
#     remark: Optional[str] = Field(None)


# class OverhaulScheduleUpdate(OverhaulScheduleBase):
#     start: datetime
#     finish: datetime


# class OverhaulScheduleRead(OverhaulScheduleBase):
#     id: UUID
#     year: int
#     plan_duration: Optional[int]
#     planned_outage: Optional[int]
#     actual_shutdown: Optional[int]
#     start: datetime
#     finish: datetime
#     remark: Optional[str]

class MasterEquipment(DefultBase):
    name: str = Field(..., max_length=100)

class CustomParameter(DefultBase):
    level: str = Field(..., max_length=50)
    failure_rates: List[float]
    mttr: float

class Equipment(EquipmentBase):
    location_tag: str = Field(..., max_length=50)
    master_equipment: MasterEquipment

class EquipmentWithCustomParameters(Equipment):
    custom_parameters: List[CustomParameter] = []

class EquipmentRead(EquipmentBase):
    AerosData: dict
    MasterData: Equipment

class EquipmentPagination(Pagination):
    items: List[EquipmentRead] = []
class FlowrateUnit(str, Enum):
    PER_DAY = "PerDay"
    PER_HOUR = "PerHour"
    PER_MINUTE = "PerMinute"


# class DistributionType(str, Enum):
#     LOGNORMAL = "Lognormal"
#     NORMAL = "Normal"
#     FIXED = "Fixed"
#     UNIFORM = "Uniform"
#     EXPONENTIAL = "Exponential"


class UnitCode(str, Enum):
    U_DAY = "UDay"
    U_HOUR = "UHour"
    U_MINUTE = "UMinute"


class EquipmentConfiguration(EquipmentBase):
    """
    Schema for equipment configuration with flow rates and distribution parameters
    """

    equipment_name: str = Field(
        ..., alias="equipmentName", description="Name of the equipment", max_length=100
    )
    max_flowrate: float = Field(
        ..., alias="maxFlowrate", ge=0, description="Maximum flow rate"
    )
    design_flowrate: float = Field(
        ..., alias="designFlowrate", ge=0, description="Design flow rate"
    )
    flowrate_unit: FlowrateUnit = Field(
        ..., alias="flowrateUnit", description="Unit for flow rate"
    )

    # Reliability Distribution Parameters
    rel_dis_type: str = Field(
        ..., alias="relDisType", description="Reliability distribution type", max_length=50
    )
    rel_dis_p1: float = Field(
        ..., alias="relDisP1", description="Reliability distribution parameter 1"
    )
    rel_dis_p2: float = Field(
        ..., alias="relDisP2", description="Reliability distribution parameter 2"
    )
    rel_dis_p3: float = Field(
        ..., alias="relDisP3", description="Reliability distribution parameter 3"
    )
    rel_dis_unit_code: UnitCode = Field(
        ..., alias="relDisUnitCode", description="Reliability distribution unit code"
    )

    # Corrective Maintenance Distribution Parameters
    cm_dis_type: str = Field(
        ..., alias="cmDisType", description="Corrective maintenance distribution type", max_length=50
    )
    cm_dis_p1: float = Field(
        ...,
        alias="cmDisP1",
        description="Corrective maintenance distribution parameter 1",
    )
    cm_dis_p2: float = Field(
        ...,
        alias="cmDisP2",
        description="Corrective maintenance distribution parameter 2",
    )
    cm_dis_p3: float = Field(
        ...,
        alias="cmDisP3",
        description="Corrective maintenance distribution parameter 3",
    )
    cm_dis_unit_code: UnitCode = Field(
        ...,
        alias="cmDisUnitCode",
        description="Corrective maintenance distribution unit code",
    )

    # Inspection Distribution Parameters
    ip_dis_type: str = Field(
        ..., alias="ipDisType", description="Inspection distribution type", max_length=50
    )
    ip_dis_p1: float = Field(
        ..., alias="ipDisP1", description="Inspection distribution parameter 1"
    )
    ip_dis_p2: float = Field(
        ..., alias="ipDisP2", description="Inspection distribution parameter 2"
    )
    ip_dis_p3: float = Field(
        ..., alias="ipDisP3", description="Inspection distribution parameter 3"
    )
    ip_dis_unit_code: UnitCode = Field(
        ..., alias="ipDisUnitCode", description="Inspection distribution unit code"
    )

    # Preventive Maintenance Distribution Parameters
    pm_dis_type: str = Field(
        ..., alias="pmDisType", description="Preventive maintenance distribution type", max_length=50
    )
    pm_dis_p1: float = Field(
        ...,
        alias="pmDisP1",
        description="Preventive maintenance distribution parameter 1",
    )
    pm_dis_p2: float = Field(
        ...,
        alias="pmDisP2",
        description="Preventive maintenance distribution parameter 2",
    )
    pm_dis_p3: float = Field(
        ...,
        alias="pmDisP3",
        description="Preventive maintenance distribution parameter 3",
    )
    pm_dis_unit_code: UnitCode = Field(
        ...,
        alias="pmDisUnitCode",
        description="Preventive maintenance distribution unit code",
    )

    # Overhaul Distribution Parameters
    oh_dis_type: str = Field(
        ..., alias="ohDisType", description="Overhaul distribution type", max_length=50
    )
    oh_dis_p1: float = Field(
        ..., alias="ohDisP1", description="Overhaul distribution parameter 1"
    )
    oh_dis_p2: float = Field(
        ..., alias="ohDisP2", description="Overhaul distribution parameter 2"
    )
    oh_dis_p3: float = Field(
        ..., alias="ohDisP3", description="Overhaul distribution parameter 3"
    )
    oh_dis_unit_code: UnitCode = Field(
        ..., alias="ohDisUnitCode", description="Overhaul distribution unit code"
    )


class EquipmentSimulation(EquipmentBase):
    location_tags: list 