# coding: utf-8

"""
    Organizze API

    Specification for the Organizze API described in [https://github.com/organizze/api-doc](https://github.com/organizze/api-doc)

    The version of the OpenAPI document: 1.0.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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class Category(BaseModel):
    """
    Category
    """ # noqa: E501
    id: Annotated[int, Field(le=2147483647, strict=True, ge=1)]
    name: StrictStr
    color: Annotated[str, Field(min_length=6, strict=True, max_length=6)]
    parent_id: Optional[Annotated[int, Field(le=2147483647, strict=True, ge=1)]]
    group_id: StrictStr
    fixed: StrictBool
    essential: StrictBool
    default: StrictBool
    uuid: StrictStr
    kind: StrictStr
    archived: StrictBool
    __properties: ClassVar[List[str]] = ["id", "name", "color", "parent_id", "group_id", "fixed", "essential", "default", "uuid", "kind", "archived"]

    @field_validator('color')
    def color_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^[a-fA-F0-9]{6}$", value):
            raise ValueError(r"must validate the regular expression /^[a-fA-F0-9]{6}$/")
        return value

    @field_validator('kind')
    def kind_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['expenses', 'earnings', 'none']):
            raise ValueError("must be one of enum values ('expenses', 'earnings', 'none')")
        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 Category 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,
        )
        # set to None if parent_id (nullable) is None
        # and model_fields_set contains the field
        if self.parent_id is None and "parent_id" in self.model_fields_set:
            _dict['parent_id'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "name": obj.get("name"),
            "color": obj.get("color"),
            "parent_id": obj.get("parent_id"),
            "group_id": obj.get("group_id"),
            "fixed": obj.get("fixed"),
            "essential": obj.get("essential"),
            "default": obj.get("default"),
            "uuid": obj.get("uuid"),
            "kind": obj.get("kind"),
            "archived": obj.get("archived")
        })
        return _obj


