# generated by fastapi-codegen:
#   filename:  /Users/apuvvadi/Workspace/guardicore-SO-contracts/contracts/guardicore/connector
#   timestamp: 2026-04-01T10:27:26+00:00

from __future__ import annotations

from typing import List, Optional

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

from centra_sdk.utils.gc_serializer import GcSerializer


class VendorACL(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    type: str = Field(..., description="ACL type (e.g., 'role')", examples=['role'])
    mac: str = Field(
        ..., description='Media Access Control address', examples=['c6:39:92:2b:37:9f']
    )
    port: str = Field(..., description='Port number or identifier', examples=['10002'])
    role_id: str = Field(
        ..., alias='role-id', description='Role identifier', examples=['Camera']
    )
    acl: str = Field(
        ...,
        description='Access Control List rules',
        examples=['in|permit ip any any\n'],
    )
    enforcement_timestamp: AwareDatetime = Field(
        ...,
        alias='enforcement-timestamp',
        description='Timestamp when the ACL was enforced',
        examples=['2026-03-30T19:48:08Z'],
    )


class SwitchObservabilityItem(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    id: str = Field(
        ...,
        description='Switch identifier (IP address or CIDR range)',
        examples=['10.255.255.2'],
    )
    vendor_acls: Optional[List[VendorACL]] = Field(
        None,
        alias='vendor-acls',
        description='List of vendor ACLs applied to the switch',
    )
    visibility_timestamp: AwareDatetime = Field(
        ...,
        alias='visibility-timestamp',
        description='Timestamp of when the switch observability data was collected',
        examples=['2026-03-30T19:47:17Z'],
    )
    latest_enforcement_timestamp: Optional[AwareDatetime] = Field(
        None,
        alias='latest-enforcement-timestamp',
        description='Timestamp of the latest enforcement action on Switch',
        examples=['2026-03-30T19:48:08Z'],
    )


class SwitchObservability(RootModel[List[SwitchObservabilityItem]]):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    root: List[SwitchObservabilityItem]

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

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