# coding: utf-8

"""
    Verity471 Unified API

      - creds: 1.0.1
  - indicators: 1.0.0
  - malware: 1.0.0
  - reports: 1.0.0
  - sources: 1.0.2
  - actors: 1.0.1
  - watchers: 1.0.0
  - observables: 1.0.0
  - entities: 1.0.0
  - girs: 1.0.0


    The version of the OpenAPI document: 1.1.1
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from verity471.models.attachment_classification import AttachmentClassification
from verity471.models.highlight import Highlight
from verity471.models.processing_status import ProcessingStatus
from verity471.models.reporting_status import ReportingStatus
from typing import Optional, Set, TYPE_CHECKING
from typing_extensions import Self

if TYPE_CHECKING:
    # Only for type checkers; does not run at runtime.
    from verity471.verity_stix import STIXMapperSettings


class AttachmentData(BaseModel):
    """
    AttachmentData
    """ # noqa: E501
    attachment_highlights: Optional[List[StrictStr]] = None
    attachment_original_url: Optional[StrictStr] = None
    classification: Optional[AttachmentClassification] = None
    dimensions: Optional[StrictStr] = None
    file_available: StrictBool
    file_hash: StrictStr
    file_name: StrictStr
    file_size: StrictInt
    file_url: Optional[StrictStr] = None
    highlights: Optional[List[Highlight]] = None
    id: StrictStr
    is_not_image: StrictBool
    mime_type: StrictStr
    original_height: Optional[StrictInt] = None
    original_width: Optional[StrictInt] = None
    processing_status: ProcessingStatus
    recognized_logos: Optional[StrictStr] = None
    recognized_text: Optional[StrictStr] = None
    reporting_status: ReportingStatus
    source_entity_id: StrictStr
    thumbnail_available: StrictBool
    thumbnail_height: Optional[StrictInt] = None
    thumbnail_width: Optional[StrictInt] = None
    webp_available: StrictBool
    __properties: ClassVar[List[str]] = ["attachment_highlights", "attachment_original_url", "classification", "dimensions", "file_available", "file_hash", "file_name", "file_size", "file_url", "highlights", "id", "is_not_image", "mime_type", "original_height", "original_width", "processing_status", "recognized_logos", "recognized_text", "reporting_status", "source_entity_id", "thumbnail_available", "thumbnail_height", "thumbnail_width", "webp_available"]

    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_stix(self, settings: Optional["STIXMapperSettings"] = None):
        try:
            from verity471.verity_stix.mappers.common import StixMapper
        except ImportError as e:
            raise ImportError(
                "STIX support is an optional feature. "
                "Install with: pip install 'verity471[stix]'"
            ) from e
        stix_mapper = StixMapper(settings)
        return stix_mapper.map(self.to_dict())

    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 AttachmentData 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 each item in highlights (list)
        _items = []
        if self.highlights:
            for _item_highlights in self.highlights:
                if _item_highlights:
                    _items.append(_item_highlights.to_dict())
            _dict['highlights'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "attachment_highlights": obj.get("attachment_highlights"),
            "attachment_original_url": obj.get("attachment_original_url"),
            "classification": obj.get("classification"),
            "dimensions": obj.get("dimensions"),
            "file_available": obj.get("file_available"),
            "file_hash": obj.get("file_hash"),
            "file_name": obj.get("file_name"),
            "file_size": obj.get("file_size"),
            "file_url": obj.get("file_url"),
            "highlights": [Highlight.from_dict(_item) for _item in obj["highlights"]] if obj.get("highlights") is not None else None,
            "id": obj.get("id"),
            "is_not_image": obj.get("is_not_image"),
            "mime_type": obj.get("mime_type"),
            "original_height": obj.get("original_height"),
            "original_width": obj.get("original_width"),
            "processing_status": obj.get("processing_status"),
            "recognized_logos": obj.get("recognized_logos"),
            "recognized_text": obj.get("recognized_text"),
            "reporting_status": obj.get("reporting_status"),
            "source_entity_id": obj.get("source_entity_id"),
            "thumbnail_available": obj.get("thumbnail_available"),
            "thumbnail_height": obj.get("thumbnail_height"),
            "thumbnail_width": obj.get("thumbnail_width"),
            "webp_available": obj.get("webp_available")
        })
        return _obj


