# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 3.54.3-ai-plus
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class Credential(BaseModel):
    """
    Credential
    """ # noqa: E501
    entity_id: StrictStr = Field(alias="entityId")
    name: Annotated[str, Field(strict=True, max_length=1000)]
    name_override: Optional[Annotated[str, Field(strict=True, max_length=1000)]] = None
    description: Optional[StrictStr] = None
    criteria_url: StrictStr = Field(alias="criteriaUrl")
    criteria_narrative: StrictStr = Field(alias="criteriaNarrative")
    created_at: datetime = Field(alias="createdAt")
    icon_image: StrictStr = Field(alias="iconImage")
    icon_image_id: StrictInt
    background_image: StrictStr = Field(alias="backgroundImage")
    background_image_id: StrictInt
    thumbnail_image: StrictStr = Field(alias="thumbnailImage")
    thumbnail_image_id: StrictInt
    catalog_items: List[StrictStr]
    courses: List[Dict[str, StrictStr]]
    programs: StrictStr
    issuer_details: Dict[str, StrictStr] = Field(alias="issuerDetails")
    html_template: Optional[StrictStr] = None
    css_template: Optional[StrictStr] = None
    metadata: Optional[Any] = None
    credential_type: StrictStr = Field(alias="credentialType")
    expires: Dict[str, StrictInt]
    tags: Optional[Any] = None
    signatories: List[Dict[str, StrictStr]]
    signal: StrictStr
    pathways: List[Dict[str, StrictStr]]
    __properties: ClassVar[List[str]] = ["entityId", "name", "name_override", "description", "criteriaUrl", "criteriaNarrative", "createdAt", "iconImage", "icon_image_id", "backgroundImage", "background_image_id", "thumbnailImage", "thumbnail_image_id", "catalog_items", "courses", "programs", "issuerDetails", "html_template", "css_template", "metadata", "credentialType", "expires", "tags", "signatories", "signal", "pathways"]

    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 Credential 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([
            "icon_image",
            "background_image",
            "thumbnail_image",
            "catalog_items",
            "courses",
            "programs",
            "issuer_details",
            "expires",
            "signatories",
            "pathways",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # set to None if name_override (nullable) is None
        # and model_fields_set contains the field
        if self.name_override is None and "name_override" in self.model_fields_set:
            _dict['name_override'] = 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 html_template (nullable) is None
        # and model_fields_set contains the field
        if self.html_template is None and "html_template" in self.model_fields_set:
            _dict['html_template'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "entityId": obj.get("entityId"),
            "name": obj.get("name"),
            "name_override": obj.get("name_override"),
            "description": obj.get("description"),
            "criteriaUrl": obj.get("criteriaUrl"),
            "criteriaNarrative": obj.get("criteriaNarrative"),
            "createdAt": obj.get("createdAt"),
            "iconImage": obj.get("iconImage"),
            "icon_image_id": obj.get("icon_image_id"),
            "backgroundImage": obj.get("backgroundImage"),
            "background_image_id": obj.get("background_image_id"),
            "thumbnailImage": obj.get("thumbnailImage"),
            "thumbnail_image_id": obj.get("thumbnail_image_id"),
            "catalog_items": obj.get("catalog_items"),
            "courses": obj.get("courses"),
            "programs": obj.get("programs"),
            "issuerDetails": obj.get("issuerDetails"),
            "html_template": obj.get("html_template"),
            "css_template": obj.get("css_template"),
            "metadata": obj.get("metadata"),
            "credentialType": obj.get("credentialType"),
            "expires": obj.get("expires"),
            "tags": obj.get("tags"),
            "signatories": obj.get("signatories"),
            "signal": obj.get("signal"),
            "pathways": obj.get("pathways")
        })
        return _obj


