#  Copyright © 2025 Bentley Systems, Incorporated
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#      http://www.apache.org/licenses/LICENSE-2.0
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

# generated by datamodel-codegen:
#   filename:  colormap.yaml

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Annotated, Any
from uuid import UUID

from pydantic import (
    AnyUrl,
    Field,
    RootModel,
    StrictBool,
    StrictFloat,
    StrictInt,
    StrictStr,
)

from .._model_config import CustomBaseModel


class AttributeAssociationData(CustomBaseModel):
    attribute_id: Annotated[StrictStr, Field(title="Attribute Id")]
    colormap_id: Annotated[UUID, Field(title="Colormap Id")]


class AttributeAssociationsData(CustomBaseModel):
    associations: Annotated[
        list[AttributeAssociationData],
        Field(max_length=128, min_length=1, title="Associations"),
    ]


class AttributeColormapAssociation(CustomBaseModel):
    attribute_id: Annotated[StrictStr, Field(title="Attribute ID")]
    colormap_id: Annotated[UUID, Field(title="Colormap ID")]
    colormap_uri: Annotated[AnyUrl, Field(title="Colormap URI")]
    created_at: datetime = Field(..., title="Created at")
    created_by: Annotated[UUID, Field(title="Created by")]
    id: Annotated[UUID, Field(title="ID")]
    modified_at: datetime = Field(..., title="Modified at")
    modified_by: Annotated[UUID, Field(title="Modified by")]
    self_link: Annotated[AnyUrl, Field(title="Self link")]
    workspace_id: Annotated[UUID, Field(title="Workspace ID")]


class AttributeColormapAssociationList(CustomBaseModel):
    associations: Annotated[list[AttributeColormapAssociation], Field(title="Associations")]


class ColorItem(RootModel[StrictInt]):
    root: StrictInt


class Color(RootModel[list[ColorItem]]):
    root: Annotated[list[ColorItem], Field(max_length=3, min_length=3)]


class ColormapTypeEnum(Enum):
    continuous = "continuous"
    category = "category"
    discrete = "discrete"


class CategoryColormapData(CustomBaseModel):
    colors: Annotated[list[Color], Field(max_length=16384, min_length=1, title="Colors")]
    """
    An ordered list of RGB colors, containing between 1 and 16384 colors. Each color is represented by three integer values (for Red, Green, and Blue) ranging from 0 to 255.
    """
    dtype: ColormapTypeEnum = ColormapTypeEnum.category
    map: Annotated[list[StrictStr], Field(title="Map")]
    name: Annotated[StrictStr, Field(title="Name")]


class ContinuousColormapData(CustomBaseModel):
    attribute_controls: Annotated[list[StrictFloat], Field(min_length=2, title="Attribute Controls")]
    colors: Annotated[list[Color], Field(max_length=1024, min_length=2, title="Colors")]
    """
    An ordered list of RGB colors, containing between 2 and 1024 colors. Each color is represented by three integer values (for Red, Green, and Blue) ranging from 0 to 255.
    """
    dtype: ColormapTypeEnum = ColormapTypeEnum.continuous
    gradient_controls: Annotated[list[StrictFloat], Field(min_length=2, title="Gradient Controls")]
    name: Annotated[StrictStr, Field(title="Name")]


class ContinuousColormapResponse(CustomBaseModel):
    attribute_controls: Annotated[list[StrictFloat], Field(min_length=1, title="Attribute controls")]
    """
    List of ordered attribute values for gradient curve
    """
    colors: Annotated[list[Color], Field(max_length=1024, min_length=2, title="Colors")]
    """
    An ordered list of RGB colors, containing between 2 and 1024 colors. Each color is represented by three integer values (for Red, Green, and Blue) ranging from 0 to 255.
    """
    created_at: datetime = Field(..., title="Created at")
    created_by: Annotated[UUID, Field(title="Created by")]
    gradient_controls: Annotated[list[StrictFloat], Field(min_length=1, title="Gradient controls")]
    """
    List of gradient positions for gradient curve, floats between 0 and 1
    """
    id: Annotated[UUID, Field(title="ID")]
    modified_at: datetime = Field(..., title="Modified at")
    modified_by: Annotated[UUID, Field(title="Modified by")]
    name: Annotated[StrictStr, Field(title="Name")]
    schema_: Annotated[ColormapTypeEnum, Field(alias="schema")]
    self_link: Annotated[AnyUrl, Field(title="Self link")]


class DiscreteColormapData(CustomBaseModel):
    colors: Annotated[list[Color], Field(max_length=1024, min_length=1, title="Colors")]
    """
    An ordered list of RGB colors, containing between 1 and 1024 colors. Each color is represented by three integer values (for Red, Green, and Blue) ranging from 0 to 255.
    """
    dtype: ColormapTypeEnum = ColormapTypeEnum.discrete
    end_inclusive: Annotated[list[StrictBool], Field(title="End Inclusive")]
    end_points: Annotated[list[StrictFloat], Field(title="End Points")]
    name: Annotated[StrictStr, Field(title="Name")]


class DiscreteColormapResponse(CustomBaseModel):
    colors: Annotated[list[Color], Field(max_length=1024, min_length=1, title="Colors")]
    """
    An ordered list of RGB colors, containing between 1 and 1024 colors. Each color is represented by three integer values (for Red, Green, and Blue) ranging from 0 to 255.
    """
    created_at: datetime = Field(..., title="Created at")
    created_by: Annotated[UUID, Field(title="Created by")]
    end_inclusive: Annotated[list[StrictBool], Field(title="End inclusive")]
    """
    Boolean array indicating whether to include the endpoint in the bucket or not
    """
    end_points: Annotated[list[StrictFloat], Field(title="End points")]
    """
    List of colormap bucket endpoints, must be one fewer than the number of colors
    """
    id: Annotated[UUID, Field(title="ID")]
    modified_at: datetime = Field(..., title="Modified at")
    modified_by: Annotated[UUID, Field(title="Modified by")]
    name: Annotated[StrictStr, Field(title="Name")]
    schema_: Annotated[ColormapTypeEnum, Field(alias="schema")]
    self_link: Annotated[AnyUrl, Field(title="Self link")]


class WorkspaceMetadataResponse(CustomBaseModel):
    objects_metadata: Annotated[dict[str, Any], Field(title="Object metadata")]
    """
    Mapping of objects to their respective metadata
    """
    workspace_id: Annotated[UUID, Field(title="Workspace ID")]


class CategoryColormapResponse(CustomBaseModel):
    colors: Annotated[list[Color], Field(max_length=16384, min_length=1, title="Colors")]
    """
    An ordered list of RGB colors, containing between 1 and 16384 colors. Each color is represented by three integer values (for Red, Green, and Blue) ranging from 0 to 255.
    """
    created_at: datetime = Field(..., title="Created at")
    created_by: Annotated[UUID, Field(title="Created by")]
    id: Annotated[UUID, Field(title="ID")]
    map: Annotated[list[StrictStr], Field(title="Map")]
    """
    String array mapping arbitrary strings to colors
    """
    modified_at: datetime = Field(..., title="Modified at")
    modified_by: Annotated[UUID, Field(title="Modified by")]
    name: Annotated[StrictStr, Field(title="Name")]
    schema_: Annotated[ColormapTypeEnum, Field(alias="schema")]
    self_link: Annotated[AnyUrl, Field(title="Self link")]


class ColormapData(RootModel[ContinuousColormapData | DiscreteColormapData | CategoryColormapData]):
    root: ContinuousColormapData | DiscreteColormapData | CategoryColormapData = Field(..., title="Colormap Data")


class ColormapResponseList(CustomBaseModel):
    colormaps: list[CategoryColormapResponse | DiscreteColormapResponse | ContinuousColormapResponse] = Field(
        ..., title="Colormaps"
    )


class ResponseGetColormapByID(
    RootModel[ContinuousColormapResponse | CategoryColormapResponse | DiscreteColormapResponse]
):
    root: ContinuousColormapResponse | CategoryColormapResponse | DiscreteColormapResponse = Field(  # noqa: E501
        ..., title="ResponseGetColormapByID"
    )


class ResponsePostColormap(RootModel[ContinuousColormapResponse | CategoryColormapResponse | DiscreteColormapResponse]):
    root: ContinuousColormapResponse | CategoryColormapResponse | DiscreteColormapResponse = Field(  # noqa: E501
        ..., title="ResponsePostColormap"
    )
