# coding: utf-8

"""
    ETAPI

    External Trilium API  # noqa: E501

    The version of the OpenAPI document: 1.0.0
    Contact: zadam.apps@gmail.com
    Generated by: https://openapi-generator.tech
"""


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


from typing import List, Optional
from pydantic import BaseModel, Field, StrictBool, StrictStr, constr, validator
from trilium_client.models.attribute import Attribute


class Note(BaseModel):
    """NOTE: This class is auto generated by OpenAPI Generator.
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    note_id: Optional[constr(strict=True)] = Field(None, alias="noteId")
    title: Optional[StrictStr] = None
    type: Optional[StrictStr] = None
    mime: Optional[StrictStr] = None
    is_protected: Optional[StrictBool] = Field(None, alias="isProtected")
    blob_id: Optional[StrictStr] = Field(
        None,
        alias="blobId",
        description="ID of the blob object which effectively serves as a content hash",
    )
    attributes: Optional[List[Attribute]] = None
    parent_note_ids: Optional[List[constr(strict=True)]] = Field(
        None, alias="parentNoteIds"
    )
    child_note_ids: Optional[List[constr(strict=True)]] = Field(
        None, alias="childNoteIds"
    )
    parent_branch_ids: Optional[List[constr(strict=True)]] = Field(
        None, alias="parentBranchIds"
    )
    child_branch_ids: Optional[List[constr(strict=True)]] = Field(
        None, alias="childBranchIds"
    )
    date_created: Optional[constr(strict=True)] = Field(
        None, alias="dateCreated"
    )
    date_modified: Optional[constr(strict=True)] = Field(
        None, alias="dateModified"
    )
    utc_date_created: Optional[constr(strict=True)] = Field(
        None, alias="utcDateCreated"
    )
    utc_date_modified: Optional[constr(strict=True)] = Field(
        None, alias="utcDateModified"
    )
    __properties = [
        "noteId",
        "title",
        "type",
        "mime",
        "isProtected",
        "blobId",
        "attributes",
        "parentNoteIds",
        "childNoteIds",
        "parentBranchIds",
        "childBranchIds",
        "dateCreated",
        "dateModified",
        "utcDateCreated",
        "utcDateModified",
    ]

    @validator("note_id")
    def note_id_validate_regular_expression(cls, v):
        if not re.match(r"[a-zA-Z0-9_]{4,32}", v):
            raise ValueError(
                r"must validate the regular expression /[a-zA-Z0-9_]{4,32}/"
            )
        return v

    @validator("type")
    def type_validate_enum(cls, v):
        if v is None:
            return v

        if v not in (
            "text",
            "code",
            "render",
            "file",
            "image",
            "search",
            "relationMap",
            "book",
            "noteMap",
            "mermaid",
            "webView",
            "shortcut",
            "doc",
            "contentWidget",
            "launcher",
        ):
            raise ValueError(
                "must validate the enum values ('text', 'code', 'render', 'file', 'image', 'search', 'relationMap', 'book', 'noteMap', 'mermaid', 'webView', 'shortcut', 'doc', 'contentWidget', 'launcher')"
            )
        return v

    @validator("date_created")
    def date_created_validate_regular_expression(cls, v):
        if not re.match(
            r"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}[\+\-][0-9]{4}",
            v,
        ):
            raise ValueError(
                r"must validate the regular expression /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}[\+\-][0-9]{4}/"
            )
        return v

    @validator("date_modified")
    def date_modified_validate_regular_expression(cls, v):
        if not re.match(
            r"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}[\+\-][0-9]{4}",
            v,
        ):
            raise ValueError(
                r"must validate the regular expression /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}[\+\-][0-9]{4}/"
            )
        return v

    @validator("utc_date_created")
    def utc_date_created_validate_regular_expression(cls, v):
        if not re.match(
            r"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z",
            v,
        ):
            raise ValueError(
                r"must validate the regular expression /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z/"
            )
        return v

    @validator("utc_date_modified")
    def utc_date_modified_validate_regular_expression(cls, v):
        if not re.match(
            r"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z",
            v,
        ):
            raise ValueError(
                r"must validate the regular expression /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{3}Z/"
            )
        return v

    class Config:
        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) -> Note:
        """Create an instance of Note 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={
                "is_protected",
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in attributes (list)
        _items = []
        if self.attributes:
            for _item in self.attributes:
                if _item:
                    _items.append(_item.to_dict())
            _dict["attributes"] = _items
        return _dict

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

        if type(obj) is not dict:
            return Note.parse_obj(obj)

        _obj = Note.parse_obj(
            {
                "note_id": obj.get("noteId"),
                "title": obj.get("title"),
                "type": obj.get("type"),
                "mime": obj.get("mime"),
                "is_protected": obj.get("isProtected"),
                "blob_id": obj.get("blobId"),
                "attributes": [
                    Attribute.from_dict(_item)
                    for _item in obj.get("attributes")
                ]
                if obj.get("attributes") is not None
                else None,
                "parent_note_ids": obj.get("parentNoteIds"),
                "child_note_ids": obj.get("childNoteIds"),
                "parent_branch_ids": obj.get("parentBranchIds"),
                "child_branch_ids": obj.get("childBranchIds"),
                "date_created": obj.get("dateCreated"),
                "date_modified": obj.get("dateModified"),
                "utc_date_created": obj.get("utcDateCreated"),
                "utc_date_modified": obj.get("utcDateModified"),
            }
        )
        return _obj
