# generated by fastapi-codegen:
#   filename:  /Users/jgopalak/Documents/projects/contracts/guardicore/connector
#   timestamp: 2026-03-12T06:37:37+00:00

from __future__ import annotations

from enum import Enum
from typing import Any, Dict, List

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

from centra_sdk.utils.gc_serializer import GcSerializer


class Severity(Enum):
    INFO = 'INFO'
    WARNING = 'WARNING'
    ERROR = 'ERROR'


class FlowlogMessage(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    details: Dict[str, Any] = Field(
        ...,
        description='Generic key-value map of contextual details for this message. For flowlog messages, contains `flowlog-id` (the AWS Flow Log ID).',
        examples=[{'flowlog-id': 'fl-0abc123def456789'}],
    )
    title: str = Field(
        ...,
        description='Short human-readable title for the message.',
        examples=['Prefix Mismatch'],
    )
    severity: Severity = Field(
        ..., description='Severity level of the message.', examples=['ERROR']
    )
    message: str = Field(
        ...,
        description='Full human-readable message describing the validation result or error.',
        examples=[
            "The prefix in the flowlog configuration ('logs/') does not match the expected prefix ('vpc-logs/')."
        ],
    )
    timestamp: AwareDatetime = Field(
        ...,
        description='ISO 8601 timestamp (with timezone) of when this message was generated.',
        examples=['2026-03-03T10:00:00+00:00'],
    )


class VpcFlowlogInfo(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    network_name: str = Field(
        ...,
        alias='network-name',
        description='The human-readable name of the network (VPC/VNet). If no name is provided, defaults to the network ID.',
        examples=['my-production-vpc'],
    )
    account_id: str = Field(
        ...,
        alias='account-id',
        description='The AWS account ID that owns this VPC.',
        examples=['123456789012'],
    )
    is_valid: bool = Field(
        ...,
        alias='is-valid',
        description='Whether the VPC has at least one valid flowlog configuration. `true` means at least one flowlog passed all validation checks. `false` means no valid flowlog was found (or no flowlogs exist).\n',
        examples=[True],
    )
    assets: conint(ge=0) = Field(
        ...,
        description='Number of assets (EC2 instances, etc.) present in this VPC.',
        examples=[12],
    )
    messages: List[FlowlogMessage] = Field(
        ...,
        description='List of warning/error/info messages for the flowlog(s) associated with this VPC. When `is-valid` is `true`, this list is empty. When `is-valid` is `false`, contains WARNING and/or ERROR messages from invalid flowlog configurations.\n',
    )


class ErrorResponse(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    error: str = Field(
        ...,
        description='Human-readable error description.',
        examples=['Internal error'],
    )


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

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

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