# generated by datamodel-codegen:
#   filename:  environment.json
#   timestamp: 2026-01-25T13:38:24+00:00

from __future__ import annotations

from enum import StrEnum
from typing import Annotated

from pydantic import AwareDatetime, BaseModel, ConfigDict, Field


class Type(StrEnum):
    """
    Data type of the variable
    """

    string = 'string'
    number = 'number'
    boolean = 'boolean'
    url = 'url'
    file = 'file'
    json = 'json'
    array = 'array'


class GlobalVariable(BaseModel):
    """
    A global variable available across all environments
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    id: Annotated[str, Field(max_length=50, min_length=1, pattern='^[a-zA-Z0-9_-]+$')]
    """
    Unique identifier for the global variable
    """
    name: Annotated[
        str, Field(max_length=50, min_length=1, pattern='^[a-zA-Z_][a-zA-Z0-9_]*$')
    ]
    """
    Variable name used in flows
    """
    value: Annotated[str, Field(max_length=10000, min_length=0)]
    """
    The variable's value
    """
    type: Type
    """
    Data type of the variable
    """
    description: Annotated[str | None, Field(max_length=500)] = None
    """
    Description of the variable's purpose
    """
    createdAt: AwareDatetime | None = None
    """
    ISO 8601 timestamp when the variable was created
    """
    updatedAt: AwareDatetime | None = None
    """
    ISO 8601 timestamp when the variable was last updated
    """


class Variable(BaseModel):
    """
    An environment-specific variable
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    id: Annotated[str, Field(max_length=50, min_length=1, pattern='^[a-zA-Z0-9_-]+$')]
    """
    Unique identifier for the variable within this environment
    """
    name: Annotated[
        str, Field(max_length=50, min_length=1, pattern='^[a-zA-Z_][a-zA-Z0-9_]*$')
    ]
    """
    Variable name used in flows
    """
    value: Annotated[str, Field(max_length=10000, min_length=0)]
    """
    The variable's value
    """
    type: Type
    """
    Data type of the variable
    """
    description: Annotated[str | None, Field(max_length=500)] = None
    """
    Description of the variable's purpose
    """


class Environment(BaseModel):
    """
    An environment configuration with its variables
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    id: Annotated[str, Field(max_length=50, min_length=1, pattern='^[a-zA-Z0-9_-]+$')]
    """
    Unique identifier for the environment
    """
    name: Annotated[str, Field(max_length=100, min_length=1)]
    """
    Display name for the environment
    """
    description: Annotated[str | None, Field(max_length=500)] = None
    """
    Description of the environment's purpose
    """
    variables: Annotated[list[Variable], Field(min_length=0)]
    """
    Environment-specific variables
    """
    isDefault: bool
    """
    Whether this is the default environment
    """
    createdAt: AwareDatetime
    """
    ISO 8601 timestamp when the environment was created
    """
    updatedAt: AwareDatetime
    """
    ISO 8601 timestamp when the environment was last updated
    """


class EnvironmentAndGlobalVariablesConfiguration(BaseModel):
    """
    Schema for environment configurations and global variables used in Floweb automation flows
    """

    model_config = ConfigDict(
        populate_by_name=True,
    )
    environments: Annotated[list[Environment], Field(min_length=0)]
    """
    List of available environments
    """
    globalVariables: Annotated[list[GlobalVariable], Field(min_length=0)]
    """
    List of global variables available across all environments
    """
    selectedEnvironmentId: Annotated[str | None, Field(pattern='^[a-zA-Z0-9_-]+$')] = (
        None
    )
    """
    ID of the currently selected environment
    """
