# 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 datetime import datetime
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 BankAccount(BaseModel):
    """
    BankAccount
    """ # noqa: E501
    id: Annotated[int, Field(le=2147483647, strict=True, ge=1)] = Field(description="ID of the Bank Account")
    name: Annotated[str, Field(strict=True, max_length=10000)] = Field(description="Name of the Bank Account")
    institution_id: Annotated[str, Field(strict=True, max_length=10000)]
    institution_name: Optional[Annotated[str, Field(strict=True, max_length=10000)]]
    description: Optional[Annotated[str, Field(strict=True, max_length=10000)]]
    kind: Optional[StrictStr] = None
    archived: StrictBool
    created_at: datetime
    updated_at: datetime
    default: StrictBool
    type: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["id", "name", "institution_id", "institution_name", "description", "kind", "archived", "created_at", "updated_at", "default", "type"]

    @field_validator('type')
    def type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['checking', 'savings', 'other']):
            raise ValueError("must be one of enum values ('checking', 'savings', 'other')")
        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 BankAccount 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 institution_name (nullable) is None
        # and model_fields_set contains the field
        if self.institution_name is None and "institution_name" in self.model_fields_set:
            _dict['institution_name'] = None

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of BankAccount 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"),
            "institution_id": obj.get("institution_id"),
            "institution_name": obj.get("institution_name"),
            "description": obj.get("description"),
            "kind": obj.get("kind"),
            "archived": obj.get("archived"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "default": obj.get("default"),
            "type": obj.get("type")
        })
        return _obj


