# generated by fastapi-codegen:
#   filename:  /home/circleci/project/guardicore/connector
#   timestamp: 2025-08-06T07:59:35+00:00

from __future__ import annotations

from enum import Enum
from typing import Any, Dict, List, Optional
from uuid import UUID

from pydantic import AwareDatetime, BaseModel, ConfigDict, Field, RootModel

from ..common.common import Connector


class ComponentDetails(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    component_version: Optional[str] = Field(None, alias='component-version')
    public_ip_addresses: Optional[List[str]] = Field(None, alias='public-ip-addresses')
    private_ip_addresses: Optional[List[str]] = Field(
        None, alias='private-ip-addresses'
    )
    hostname: Optional[str] = None
    dc_inventory_revision: int = Field(..., alias='dc-inventory-revision')
    policy_revision: int = Field(..., alias='policy-revision')
    config_revision: Optional[int] = Field(None, alias='config-revision')


class Status(Enum):
    UP = 'up'
    INITIALIZING = 'initializing'
    CONNECTING = 'connecting'
    STOPPED = 'stopped'
    DOWN = 'down'
    PARTIALLY_UP = 'partially_up'
    ERROR = 'error'
    MISSING = 'missing'
    VERIFYING = 'verifying'
    VERIFICATION_FAILED = 'verification_failed'


class Metric(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    name: str = Field(..., description='the metric that will be added to telegraf')
    value: float
    tag_name: Optional[str] = None
    tag_value: Optional[str] = None


class FlagTypes(Enum):
    CLOUD_APP_API_AUTHENTICATION_FAILED = 'CloudAppAPIAuthenticationFailed'
    CLOUD_APP_NON_PROTECTED_RESOURCE_DISCOVERED = (
        'CloudAppNonProtectedResourceDiscovered'
    )
    CLOUD_APP_FLOWLOG_DISABLED_NSG_DISCOVERED = 'CloudAppFlowlogDisabledNSGDiscovered'


class FlagSeverity(Enum):
    ERROR = 'ERROR'
    WARNING = 'WARNING'
    INFORMATION = 'INFORMATION'


class ComponentFlags(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    flag: FlagTypes
    raised_time: AwareDatetime
    severity: FlagSeverity
    description: str
    details: Optional[Dict[str, Any]] = None


class Flags(RootModel[List[ComponentFlags]]):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    root: List[ComponentFlags]

    def __getattr__(self, attr: str):
        return getattr(self.root, attr)

    def __iter__(self):
        for item in self.root:
            yield item


class Severity(Enum):
    INFO = 'info'
    WARNING = 'warning'
    ERROR = 'error'


class SystemEvent(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    source: Connector
    source_id: UUID = Field(..., alias='source-id')
    timestamp: AwareDatetime
    category: Optional[str] = Field(None, examples=['deployment'])
    severity: Severity
    title: str
    message: str
    additional_info: Optional[Dict[str, str]] = Field(
        None, examples=[{'region-code': 'eastus', 'region-name': 'East US'}]
    )


class V1OperationsFlagsGetResponse(RootModel[List[ComponentFlags]]):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    root: List[ComponentFlags]

    def __getattr__(self, attr: str):
        return getattr(self.root, attr)

    def __iter__(self):
        for item in self.root:
            yield item


class ComponentMetrics(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    component_id: UUID = Field(..., alias='component-id')
    component_type: str = Field(..., alias='component-type')
    component_metrics: List[Metric] = Field(..., alias='component-metrics')


class ServiceStatus(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    service_status: Status = Field(..., alias='service-status')
    msg: Optional[str] = None


class V1OperationsMetricsGetResponse(RootModel[List[ComponentMetrics]]):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    root: List[ComponentMetrics] = Field(..., min_length=1)

    def __getattr__(self, attr: str):
        return getattr(self.root, attr)

    def __iter__(self):
        for item in self.root:
            yield item


class ApplicationStatus(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    application_status: Status = Field(..., alias='application-status')
    services_status: Optional[Dict[str, ServiceStatus]] = Field(
        None, alias='services-status'
    )


class ComponentStatus(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    overall_status: Status = Field(..., alias='overall-status')
    applications_status: Optional[Dict[str, ApplicationStatus]] = Field(
        None, alias='applications-status'
    )


class ComponentHealth(BaseModel):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    component_id: UUID = Field(..., alias='component-id')
    component_type: Connector = Field(..., alias='component-type')
    component_details: ComponentDetails = Field(..., alias='component-details')
    status: ComponentStatus


class V1OperationsHealthGetResponse(RootModel[List[ComponentHealth]]):
    model_config = ConfigDict(
        populate_by_name=True,
    )
    root: List[ComponentHealth] = Field(..., min_length=1)

    def __getattr__(self, attr: str):
        return getattr(self.root, attr)

    def __iter__(self):
        for item in self.root:
            yield item
