# coding: utf-8

"""
    RobotnikAI API

    Documentation of API endpoints of RobotnikAI

    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, StrictInt, 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 Application(BaseModel):
    """
    Application
    """ # noqa: E501
    id: Optional[StrictInt] = None
    organization: Optional[StrictStr] = None
    url: Optional[StrictStr] = None
    activated: Optional[StrictBool] = None
    icon: Optional[StrictStr] = None
    configuration_schema_available: Optional[StrictBool] = None
    authorized: Optional[StrictBool] = None
    is_official: Optional[StrictBool] = None
    is_active: Optional[StrictBool] = None
    name: Annotated[str, Field(strict=True, max_length=150)]
    slug: Optional[Annotated[str, Field(strict=True)]] = None
    description: Optional[StrictStr] = None
    is_public: Optional[StrictBool] = None
    is_open_source: Optional[StrictBool] = None
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
    forked_from: Optional[StrictInt] = Field(default=None, description="If this application is a fork, this field points to the original application.")
    __properties: ClassVar[List[str]] = ["id", "organization", "url", "activated", "icon", "configuration_schema_available", "authorized", "is_official", "is_active", "name", "slug", "description", "is_public", "is_open_source", "created_at", "updated_at", "forked_from"]

    @field_validator('slug')
    def slug_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if value is None:
            return value

        if not re.match(r"^[-a-zA-Z0-9_]+$", value):
            raise ValueError(r"must validate the regular expression /^[-a-zA-Z0-9_]+$/")
        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 Application 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "id",
            "organization",
            "url",
            "activated",
            "configuration_schema_available",
            "authorized",
            "is_official",
            "slug",
            "created_at",
            "updated_at",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if organization (nullable) is None
        # and model_fields_set contains the field
        if self.organization is None and "organization" in self.model_fields_set:
            _dict['organization'] = None

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Application 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"),
            "organization": obj.get("organization"),
            "url": obj.get("url"),
            "activated": obj.get("activated"),
            "icon": obj.get("icon"),
            "configuration_schema_available": obj.get("configuration_schema_available"),
            "authorized": obj.get("authorized"),
            "is_official": obj.get("is_official"),
            "is_active": obj.get("is_active"),
            "name": obj.get("name"),
            "slug": obj.get("slug"),
            "description": obj.get("description"),
            "is_public": obj.get("is_public"),
            "is_open_source": obj.get("is_open_source"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at"),
            "forked_from": obj.get("forked_from")
        })
        return _obj


