# 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 List, Optional

from pydantic import BaseModel, ConfigDict, Field

from centra_sdk.utils.gc_serializer import GcSerializer


class OperationMode(Enum):
    REVEAL = 'reveal'
    REVEAL_AND_ENFORCEMENT = 'reveal_and_enforcement'


class BundleRequest(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    operation_mode: OperationMode = Field(
        ...,
        description='Operation mode for the onboarding: "reveal" for visibility only, "reveal_and_enforcement" for visibility and enforcement',
    )


class ServiceAccountValidationRequest(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    operation_mode: OperationMode = Field(
        ...,
        description='Operation mode to validate permissions for: "reveal" for visibility roles, "reveal_and_enforcement" for enforcement+visibility roles',
    )
    service_account_email: Optional[str] = Field(
        None,
        description='Email of the GCP service account to validate (optional, for informational purposes)',
    )


class GCPProject(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    id: str = Field(..., description='GCP Project ID')
    name: str = Field(..., description='GCP Project display name')
    parent: Optional[str] = Field(
        None,
        description='Parent folder or organization (e.g., "folders/111111" or "organizations/123456789")',
    )


class GCPFolder(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    id: str = Field(..., description='GCP Folder ID (e.g., "folders/111111")')
    name: str = Field(..., description='GCP Folder display name')
    parent: Optional[str] = Field(None, description='Parent folder or organization')
    description: Optional[str] = Field(None, description='Optional folder description')


class OrganizationTree(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    organization_id: Optional[str] = Field(None, description='GCP Organization ID')
    organization_name: Optional[str] = Field(
        None, description='GCP Organization display name'
    )
    folders: Optional[List[GCPFolder]] = Field(
        None, description='List of top-level folders in the organization'
    )


class Status(Enum):
    SUCCESS = 'success'
    PARTIAL = 'partial'


class ServiceAccountValidationSuccess(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    status: Status = Field(
        ...,
        description='Validation status: "success" if all permissions are correct, "partial" if some are missing',
    )
    message: Optional[str] = Field(
        None, description='Validation message describing the result'
    )
    projects: Optional[List[GCPProject]] = Field(
        None, description='List of accessible GCP projects'
    )
    folders: Optional[List[GCPFolder]] = Field(
        None, description='List of accessible GCP folders'
    )
    organization: Optional[OrganizationTree] = Field(
        None, description='GCP Organization hierarchy and structure'
    )
    missing_permissions: Optional[List[str]] = Field(
        None, description='List of missing IAM permissions (if status is "partial")'
    )


class Detail(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    field: Optional[str] = None
    issue: Optional[str] = None


class GCPValidationError(BaseModel, GcSerializer):
    model_config = ConfigDict(
        populate_by_name=True,
        from_attributes=True,
    )
    code: str = Field(
        ...,
        description='Error code (e.g. invalid_credentials, missing_field, insufficient_permissions)',
    )
    message: str = Field(..., description='Error message suitable for UI display')
    details: Optional[List[Detail]] = Field(
        None,
        description='Optional array with field-level issues to display in UI. Each item should include `field` and `issue`.',
    )


class Action(Enum):
    VALIDATE_VISIBILITY_ROLES = 'validate-visibility-roles'
    VALIDATE_ENFORCEMENT_ROLES = 'validate-enforcement-roles'
