# coding: utf-8

"""
    FastAPI

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1.0
    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 typing import Any, Dict, List, Optional
from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr, conlist, constr
from bia_integrator_api.models.bia_image_alias import BIAImageAlias
from bia_integrator_api.models.bia_image_representation import BIAImageRepresentation
from bia_integrator_api.models.image_annotation import ImageAnnotation
from bia_integrator_api.models.model_metadata import ModelMetadata

class BIAImage(BaseModel):
    """
    This class represents the abstract concept of an image. Images are generated by acquisition by instruments.  Examples:  * A single plane bright-field image of a bacterium. * A confocal fluorescence image of cells, with two channels. * A volume EM stack of a cell.  Images are distinct from their representation as files, since the same image can be represented in different file formats and in some cases different file structures.
    """
    attributes: Optional[Dict[str, Any]] = Field(None, description="         When annotations are applied, the ones that have a key different than an object attribute (so they don't overwrite it) get saved here.     ")
    annotations_applied: Optional[StrictBool] = Field(False, description="         This acts as a dirty flag, with the purpose of telling apart objects that had some fields overwritten by applying annotations (so should be rejected when writing), and those that didn't.     ")
    annotations: Optional[conlist(ImageAnnotation)] = None
    context: Optional[constr(strict=True, min_length=1)] = Field('https://raw.githubusercontent.com/BioImage-Archive/bia-integrator/main/api/src/models/jsonld/1.0/ImageContext.jsonld', alias="@context")
    uuid: StrictStr = Field(...)
    version: StrictInt = Field(...)
    model: Optional[ModelMetadata] = None
    study_uuid: StrictStr = Field(...)
    original_relpath: StrictStr = Field(...)
    name: Optional[StrictStr] = None
    dimensions: Optional[StrictStr] = None
    representations: Optional[conlist(BIAImageRepresentation)] = None
    alias: Optional[BIAImageAlias] = None
    image_acquisitions_uuid: Optional[conlist(StrictStr)] = Field(None, description="Context in which the image was acquired. This list often has one item, but it can occasionally have more (e.g. for multimodal imaging)")
    __properties = ["attributes", "annotations_applied", "annotations", "@context", "uuid", "version", "model", "study_uuid", "original_relpath", "name", "dimensions", "representations", "alias", "image_acquisitions_uuid"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

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

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

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

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of each item in annotations (list)
        _items = []
        if self.annotations:
            for _item in self.annotations:
                if _item:
                    _items.append(_item.to_dict())
            _dict['annotations'] = _items
        # override the default output from pydantic by calling `to_dict()` of model
        if self.model:
            _dict['model'] = self.model.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in representations (list)
        _items = []
        if self.representations:
            for _item in self.representations:
                if _item:
                    _items.append(_item.to_dict())
            _dict['representations'] = _items
        # override the default output from pydantic by calling `to_dict()` of alias
        if self.alias:
            _dict['alias'] = self.alias.to_dict()
        # set to None if model (nullable) is None
        # and __fields_set__ contains the field
        if self.model is None and "model" in self.__fields_set__:
            _dict['model'] = None

        # set to None if name (nullable) is None
        # and __fields_set__ contains the field
        if self.name is None and "name" in self.__fields_set__:
            _dict['name'] = None

        # set to None if dimensions (nullable) is None
        # and __fields_set__ contains the field
        if self.dimensions is None and "dimensions" in self.__fields_set__:
            _dict['dimensions'] = None

        # set to None if alias (nullable) is None
        # and __fields_set__ contains the field
        if self.alias is None and "alias" in self.__fields_set__:
            _dict['alias'] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> BIAImage:
        """Create an instance of BIAImage from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return BIAImage.parse_obj(obj)

        _obj = BIAImage.parse_obj({
            "attributes": obj.get("attributes"),
            "annotations_applied": obj.get("annotations_applied") if obj.get("annotations_applied") is not None else False,
            "annotations": [ImageAnnotation.from_dict(_item) for _item in obj.get("annotations")] if obj.get("annotations") is not None else None,
            "context": obj.get("@context") if obj.get("@context") is not None else 'https://raw.githubusercontent.com/BioImage-Archive/bia-integrator/main/api/src/models/jsonld/1.0/ImageContext.jsonld',
            "uuid": obj.get("uuid"),
            "version": obj.get("version"),
            "model": ModelMetadata.from_dict(obj.get("model")) if obj.get("model") is not None else None,
            "study_uuid": obj.get("study_uuid"),
            "original_relpath": obj.get("original_relpath"),
            "name": obj.get("name"),
            "dimensions": obj.get("dimensions"),
            "representations": [BIAImageRepresentation.from_dict(_item) for _item in obj.get("representations")] if obj.get("representations") is not None else None,
            "alias": BIAImageAlias.from_dict(obj.get("alias")) if obj.get("alias") is not None else None,
            "image_acquisitions_uuid": obj.get("image_acquisitions_uuid")
        })
        return _obj


