# coding: utf-8

from __future__ import annotations

from abc import ABC

from datetime import date, datetime  # noqa: F401
from enum import Enum, IntEnum

import re  # noqa: F401
from typing import Any, Dict, List, Optional, Type, Union, Callable  # noqa: F401
from pathlib import Path
from typing import TypeVar
Model = TypeVar('Model', bound='BaseModel')
StrBytes = Union[str, bytes]

from pydantic import AnyUrl, BaseModel, EmailStr, Field, validator, root_validator, Extra,PrivateAttr  # noqa: F401
from pydantic import ValidationError
from pydantic.error_wrappers import ErrorWrapper
from pydantic.utils import ROOT_KEY
from json import encoder

from dnv_bladed_models.bladed_model import BladedModel



class PitchSafetySystem_PitchSafetySystemTypeEnum(str, Enum):
    ACTUATION_LIMITED = "ActuationLimited"
    CONSTANT_RATE = "ConstantRate"
    RATE_DEMAND_SET_BY_EXTERNAL_CONTROLLER = "RateDemandSetByExternalController"
    RATE_VARIES_WITH_POSITION = "RateVariesWithPosition"
    RATE_VARIES_WITH_TIME = "RateVariesWithTime"
    TORQUE_SET_BY_EXTERNAL_CONTROLLER = "TorqueSetByExternalController"

from .schema_helper import SchemaHelper 
from .models_impl import *
from .common_base_model import CommonBaseModel

class PitchSafetySystem(BladedModel, ABC):
    r"""
    The common properties of a pitch controller&#39;s safety system.
    
    Attributes:
    ----------
    PitchSafetySystemType : PitchSafetySystem_PitchSafetySystemTypeEnum
        Defines the specific type of model in use.

    AlwaysUseBackupPower : bool, default=False
        Backup power is normally only used in a grid loss.  If true, this will trigger a switch to backup power torque limits in all safety system pitch action events.

    Notes:
    -----
    This class is an abstraction, with the following concrete implementations:
        - PitchActuationLimited
        - PitchConstantRateSafetySystem
        - PitchRateDemandSetByExternalController
        - PitchRateVariesWithPosition
        - PitchRateVariesWithTime
        - PitchTorqueSetByExternalController
    
    """
    _relative_schema_path: str = PrivateAttr('Components/PitchSystem/PitchController/PitchSafetySystem/common/PitchSafetySystem.json')
    
    PitchSafetySystemType: Optional[PitchSafetySystem_PitchSafetySystemTypeEnum] = Field(alias="PitchSafetySystemType", default=None)
    AlwaysUseBackupPower: Optional[bool] = Field(alias="AlwaysUseBackupPower", default=False)



    _subtypes_ = dict()

    def __init_subclass__(cls, PitchSafetySystemType=None):
        cls._subtypes_[PitchSafetySystemType or cls.__name__.lower()] = cls

    @classmethod
    def __get_validators__(cls):
        yield cls._discriminator_factory

    @classmethod
    def _discriminator_factory(cls, data: dict):
        if isinstance(data, dict):
            data_type = data.get("PitchSafetySystemType")
            if data_type is None:
                raise ValueError("Missing 'PitchSafetySystemType' in PitchSafetySystem")
            sub = cls._subtypes_.get(data_type)
            if sub is None:
                raise TypeError(f"Unsupported sub-type: '{data_type}' for base-type 'PitchSafetySystem'")
            return sub(**data)
        return data


PitchSafetySystem.update_forward_refs()
