# coding: utf-8

"""
    Picteus

    The Picteus API

    The version of the OpenAPI document: 0.11.0
    Contact: edouard@koppasoft.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt, field_validator
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from picteus_ws_client.models.dates import Dates
from picteus_ws_client.models.extension_image_feature import ExtensionImageFeature
from picteus_ws_client.models.extension_image_tag import ExtensionImageTag
from picteus_ws_client.models.image_dimensions import ImageDimensions
from picteus_ws_client.models.image_format import ImageFormat
from picteus_ws_client.models.image_metadata import ImageMetadata
from typing import Optional, Set
from typing_extensions import Self

class Image(BaseModel):
    """
    Comprehensive information about an image, i.e. all the information about an image
    """ # noqa: E501
    creation_date: Union[StrictFloat, StrictInt] = Field(description="The entity creation date", alias="creationDate")
    modification_date: Union[StrictFloat, StrictInt] = Field(description="The entity last modification date", alias="modificationDate")
    id: Annotated[str, Field(min_length=36, strict=True, max_length=36)] = Field(description="The unique identifier of the image")
    repository_id: Annotated[str, Field(min_length=36, strict=True, max_length=36)] = Field(description="The unique identifier of the repository it belongs to", alias="repositoryId")
    parent_id: Optional[Annotated[str, Field(min_length=36, strict=True, max_length=36)]] = Field(default=None, description="The unique identifier of the image parent", alias="parentId")
    name: Annotated[str, Field(min_length=1, strict=True, max_length=512)] = Field(description="The image name")
    format: ImageFormat = Field(description="The image format")
    mime_type: Annotated[str, Field(min_length=1, strict=True, max_length=32)] = Field(description="The image MIME type", alias="mimeType")
    uri: Annotated[str, Field(min_length=8, strict=True, max_length=4096)] = Field(description="The image URI")
    url: Annotated[str, Field(min_length=8, strict=True, max_length=4096)] = Field(description="The image URL")
    source_url: Optional[Annotated[str, Field(min_length=8, strict=True, max_length=4096)]] = Field(default=None, description="The image source URL", alias="sourceUrl")
    size_in_bytes: Union[Annotated[float, Field(strict=True, ge=0)], Annotated[int, Field(strict=True, ge=0)]] = Field(description="The image size in bytes", alias="sizeInBytes")
    dimensions: ImageDimensions = Field(description="The image dimensions")
    file_dates: Dates = Field(description="The image file dates", alias="fileDates")
    metadata: ImageMetadata = Field(description="The image metadata")
    features: List[ExtensionImageFeature] = Field(description="The image features")
    tags: List[ExtensionImageTag] = Field(description="The image tags")
    __properties: ClassVar[List[str]] = ["creationDate", "modificationDate", "id", "repositoryId", "parentId", "name", "format", "mimeType", "uri", "url", "sourceUrl", "sizeInBytes", "dimensions", "fileDates", "metadata", "features", "tags"]

    @field_validator('id')
    def id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", value):
            raise ValueError(r"must validate the regular expression /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/")
        return value

    @field_validator('repository_id')
    def repository_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", value):
            raise ValueError(r"must validate the regular expression /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/")
        return value

    @field_validator('parent_id')
    def parent_id_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", value):
            raise ValueError(r"must validate the regular expression /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/")
        return value

    @field_validator('uri')
    def uri_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"file:\/\/.*", value):
            raise ValueError(r"must validate the regular expression /file:\/\/.*/")
        return value

    @field_validator('url')
    def url_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"file:\/\/.*", value):
            raise ValueError(r"must validate the regular expression /file:\/\/.*/")
        return value

    @field_validator('source_url')
    def source_url_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^(https?):\/\/[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|]$", value):
            raise ValueError(r"must validate the regular expression /^(https?):\/\/[-a-zA-Z0-9+&@#\/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#\/%=~_|]$/")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of Image from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of dimensions
        if self.dimensions:
            _dict['dimensions'] = self.dimensions.to_dict()
        # override the default output from pydantic by calling `to_dict()` of file_dates
        if self.file_dates:
            _dict['fileDates'] = self.file_dates.to_dict()
        # override the default output from pydantic by calling `to_dict()` of metadata
        if self.metadata:
            _dict['metadata'] = self.metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in features (list)
        _items = []
        if self.features:
            for _item_features in self.features:
                if _item_features:
                    _items.append(_item_features.to_dict())
            _dict['features'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in tags (list)
        _items = []
        if self.tags:
            for _item_tags in self.tags:
                if _item_tags:
                    _items.append(_item_tags.to_dict())
            _dict['tags'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Image from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "creationDate": obj.get("creationDate"),
            "modificationDate": obj.get("modificationDate"),
            "id": obj.get("id"),
            "repositoryId": obj.get("repositoryId"),
            "parentId": obj.get("parentId"),
            "name": obj.get("name"),
            "format": obj.get("format"),
            "mimeType": obj.get("mimeType"),
            "uri": obj.get("uri"),
            "url": obj.get("url"),
            "sourceUrl": obj.get("sourceUrl"),
            "sizeInBytes": obj.get("sizeInBytes"),
            "dimensions": ImageDimensions.from_dict(obj["dimensions"]) if obj.get("dimensions") is not None else None,
            "fileDates": Dates.from_dict(obj["fileDates"]) if obj.get("fileDates") is not None else None,
            "metadata": ImageMetadata.from_dict(obj["metadata"]) if obj.get("metadata") is not None else None,
            "features": [ExtensionImageFeature.from_dict(_item) for _item in obj["features"]] if obj.get("features") is not None else None,
            "tags": [ExtensionImageTag.from_dict(_item) for _item in obj["tags"]] if obj.get("tags") is not None else None
        })
        return _obj


