# coding: utf-8

"""
    IdentityNow Beta API

    Use these APIs to interact with the IdentityNow platform to achieve repeatable, automated processes with greater scalability. These APIs are in beta and are subject to change. We encourage you to join the SailPoint Developer Community forum at https://developer.sailpoint.com/discuss to connect with other developers using our APIs.

    The version of the OpenAPI document: 3.1.0-beta
    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 typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictStr, field_validator
from pydantic import Field
from sailpoint.beta.models.license import License
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class Product(BaseModel):
    """
    Product
    """ # noqa: E501
    product_name: Optional[StrictStr] = Field(default=None, description="Name of the Product", alias="productName")
    url: Optional[StrictStr] = Field(default=None, description="URL of the Product")
    product_tenant_id: Optional[StrictStr] = Field(default=None, description="An identifier for a specific product-tenant combination", alias="productTenantId")
    product_region: Optional[StrictStr] = Field(default=None, description="Product region", alias="productRegion")
    product_right: Optional[StrictStr] = Field(default=None, description="Right needed for the Product", alias="productRight")
    api_url: Optional[StrictStr] = Field(default=None, description="API URL of the Product", alias="apiUrl")
    licenses: Optional[List[License]] = None
    attributes: Optional[Dict[str, Any]] = Field(default=None, description="Additional attributes for a product")
    zone: Optional[StrictStr] = Field(default=None, description="Zone")
    status: Optional[StrictStr] = Field(default=None, description="Status of the product")
    status_date_time: Optional[datetime] = Field(default=None, description="Status datetime", alias="statusDateTime")
    reason: Optional[StrictStr] = Field(default=None, description="If there's a tenant provisioning failure then reason will have the description of error")
    notes: Optional[StrictStr] = Field(default=None, description="Product could have additional notes added during tenant provisioning.")
    date_created: Optional[datetime] = Field(default=None, description="Date when the product was created", alias="dateCreated")
    last_updated: Optional[datetime] = Field(default=None, description="Date when the product was last updated", alias="lastUpdated")
    org_type: Optional[StrictStr] = Field(default=None, description="Type of org", alias="orgType")
    __properties: ClassVar[List[str]] = ["productName", "url", "productTenantId", "productRegion", "productRight", "apiUrl", "licenses", "attributes", "zone", "status", "statusDateTime", "reason", "notes", "dateCreated", "lastUpdated", "orgType"]

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

        if value not in ('development', 'staging', 'production', 'test', 'partner', 'training', 'demonstration', 'sandbox', 'null'):
            raise ValueError("must be one of enum values ('development', 'staging', 'production', 'test', 'partner', 'training', 'demonstration', 'sandbox', 'null')")
        return value

    model_config = {
        "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) -> Self:
        """Create an instance of Product 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.
        """
        _dict = self.model_dump(
            by_alias=True,
            exclude={
            },
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in licenses (list)
        _items = []
        if self.licenses:
            for _item in self.licenses:
                if _item:
                    _items.append(_item.to_dict())
            _dict['licenses'] = _items
        # set to None if api_url (nullable) is None
        # and model_fields_set contains the field
        if self.api_url is None and "api_url" in self.model_fields_set:
            _dict['apiUrl'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "productName": obj.get("productName"),
            "url": obj.get("url"),
            "productTenantId": obj.get("productTenantId"),
            "productRegion": obj.get("productRegion"),
            "productRight": obj.get("productRight"),
            "apiUrl": obj.get("apiUrl"),
            "licenses": [License.from_dict(_item) for _item in obj.get("licenses")] if obj.get("licenses") is not None else None,
            "attributes": obj.get("attributes"),
            "zone": obj.get("zone"),
            "status": obj.get("status"),
            "statusDateTime": obj.get("statusDateTime"),
            "reason": obj.get("reason"),
            "notes": obj.get("notes"),
            "dateCreated": obj.get("dateCreated"),
            "lastUpdated": obj.get("lastUpdated"),
            "orgType": obj.get("orgType")
        })
        return _obj


