# generated by fastapi-codegen:
#   filename:  /home/circleci/project/guardicore/connector
#   timestamp: 2025-12-16T15:57:14+00:00

from __future__ import annotations

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

from pydantic import BaseModel, ConfigDict, Field, RootModel

from centra_sdk.utils.gc_serializer import GcSerializer

from ..common.common import Connector


class Name(Enum):
    AZURE_ONBOARDING = 'AzureOnboarding'
    MISCELLANEOUS = 'miscellaneous'
    AWS_ONBOARDING = 'AwsOnboarding'


class OperationMode(Enum):
    VISIBILITY = 'visibility'
    ENFORCEMENT = 'enforcement'


class OnboardConfig(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    operation_mode: OperationMode = Field(..., alias='operation-mode')
    auto_discovery: Optional[bool] = Field(False, alias='auto-discovery')
    revision: Optional[int] = None


class Scope(Enum):
    MANAGEMENT_GROUP = 'management_group'
    SUBSCRIPTION = 'subscription'


class AzureSubscriptionsFilter(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    scope: Scope
    values: List[str] = Field(
        ...,
        examples=[
            [
                '/providers/Microsoft.Management/managementGroups/EnggMgmtGroupID',
                '/providers/Microsoft.Management/managementGroups/ProdGroupID',
            ]
        ],
    )


class Scope1(Enum):
    ORG_UNIT = 'org_unit'
    ACCOUNTS = 'accounts'


class AwsAccountsFilter(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    scope: Scope1
    values: List[str] = Field(..., examples=[['012345678901']])


class StatusRequest(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    detailed_status: Optional[Union[AzureSubscriptionsFilter, AwsAccountsFilter]] = (
        Field(None, alias='detailed-status')
    )


class Status(Enum):
    COMPLETED = 'completed'
    IN_PROGRESS = 'in_progress'
    NOT_ONBOARDED = 'not_onboarded'
    FAILED = 'failed'
    PARTIAL = 'partial'


class AzureSubscriptionsStatus(RootModel[List[Dict[str, Status]]]):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    root: List[Dict[str, Status]] = Field(
        ...,
        examples=[
            [
                {'87bd8fcb-0e02-4d5f-83e6-e045c63dd4': 'completed'},
                {'97bd8fcb-0e02-4d5f-83e6-e045c63dd4': 'in_progress'},
            ]
        ],
    )

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

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


class EnvUnitStatus(RootModel[List[Dict[str, Status]]]):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    root: List[Dict[str, Status]] = Field(
        ...,
        examples=[
            [
                {'87bd8fcb-0e02-4d5f-83e6-e045c63dd4': 'completed'},
                {'97bd8fcb-0e02-4d5f-83e6-e045c63dd4': 'in_progress'},
            ]
        ],
    )

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

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


class IntegrationCapabilities(Enum):
    INVENTORY = 'Inventory'
    ENFORCEMENT = 'Enforcement'
    REVEAL = 'Reveal'


class InfraCapabilities(Enum):
    LABEL_FILTER = 'LabelFilter'


class AzureOnboarding(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    subscriptions: AzureSubscriptionsFilter


class AwsOnboarding(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    accounts: AwsAccountsFilter


class Step1(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    step: Optional[str] = None
    status: Optional[Status] = None


class StatusResponse(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    overall_status: Status = Field(..., alias='overall-status')
    steps: Optional[List[Step1]] = None
    detailed_status: Optional[Union[AzureSubscriptionsStatus, EnvUnitStatus]] = Field(
        None, alias='detailed-status'
    )


class Step(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    name: Name
    action: Union[AzureOnboarding, AwsOnboarding, Dict[str, Any]]


class Onboard(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    connector_type: Connector = Field(..., alias='connector-type')
    component_id: UUID = Field(..., alias='component-id')
    general: OnboardConfig
    steps: List[Step]
