# coding: utf-8

"""
    Acre Platform User API

    # CORS CORS is implemented by all Acre API endpoints and only certain hostnames are allowed for each deployment of the API. If your use case requires calling the Acre User API from a browser, please contact Acre to arrange the appropriate configuration. # API Authentication The primary method of authentication for users of the Acre API is with the use of JSON Web Tokens (JWTs), which are suplemented by an application specific API Key. The API key must be provided through the `X-API-KEY` HTTP header and will be provided by your Acre Customer Success Manager. The JWT must be provided through a cookie with key of `authorization`. The JWT must be generated and signed as per the following section. # Generating JWTs JWT must either be generated by a third-party such as Azure ADB2C that has been configured for the appropriate service and/or user account, or alternatively can be generated locally and signed by an private key for which the public key has been made available to Acre via a JWKS URL. In addition to being signed by your private key, the JWT will also need to contain at a minimum:  * An issuer `iss`, which must be a valid URI previously agreed with Acre.  * A subject `sub`, which must be a unique identifier for the user and/or service account previously agreed with Acre.  * An expiry time `exp` which must not be more than four hours in the future.  * A not before time `nbf` which must be in the past, but not greater than six hours in the past.  The JWT should be signed using RS256.

    The version of the OpenAPI document: 1.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
from typing import Any, ClassVar, Dict, List, Optional
from acre_api.models.cdm_external import CdmExternal
from acre_api.models.cdm_premium_frequency import CdmPremiumFrequency
from acre_api.models.cdm_protection_commission import CdmProtectionCommission
from acre_api.models.cdm_protection_product_benefits import CdmProtectionProductBenefits
from acre_api.models.cdm_protection_product_details_status import CdmProtectionProductDetailsStatus
from acre_api.models.cdm_protection_product_documents import CdmProtectionProductDocuments
from acre_api.models.cdm_protection_product_not_proceeding import CdmProtectionProductNotProceeding
from acre_api.models.cdm_protection_source import CdmProtectionSource
from acre_api.models.protection_product_details_solution_type import ProtectionProductDetailsSolutionType
from typing import Optional, Set
from typing_extensions import Self

class CdmProtectionProductDetails(BaseModel):
    """
    ProtectionProductDetails contains protection product details.
    """ # noqa: E501
    protection_id: Optional[StrictStr] = Field(default=None, description="Property reference. Populated automatically; cannot be set.")
    provider_name: Optional[StrictStr] = Field(default=None, description="The name of the insurance provider.")
    premium_frequency: Optional[CdmPremiumFrequency] = CdmPremiumFrequency.INVALID_PREMIUM_FREQUENCY
    product_name: Optional[StrictStr] = Field(default=None, description="The name given to the product by the provider.")
    recommendation_premium_amount: Optional[StrictStr] = Field(default=None, description="The premium amount of the policy.")
    underwritten_premium_amount: Optional[StrictStr] = Field(default=None, description="The underwritten premium amount of the policy.")
    product_details: Optional[StrictStr] = Field(default=None, description="Misc notes attached to the product.")
    policy_number: Optional[StrictStr] = Field(default=None, description="The identification number of the policy.")
    start_date: Optional[StrictStr] = Field(default=None, description="The start of cover.")
    end_date: Optional[StrictStr] = Field(default=None, description="The end of cover.")
    source_response: Optional[StrictStr] = Field(default=None, description="The response from the sourcing API on which basis this product was chosen. Sourcing API response must include a signature.")
    is_employment_benefit: Optional[StrictBool] = Field(default=None, description="Is the product an employment benefit.")
    keep_existing_policy: Optional[StrictBool] = Field(default=None, description="The client is to go through their existing policies one by one and confirm which are to be cancelled as a result of the policies recommended in the case.")
    product_recommendation_justification: Optional[StrictStr] = Field(default=None, description="Why the product was recommended.")
    status: Optional[CdmProtectionProductDetailsStatus] = CdmProtectionProductDetailsStatus.INVALID_STATUS
    client_ids: Optional[List[StrictStr]] = Field(default=None, description="The client(s) to whom the product is tied.")
    case_ids: Optional[List[StrictStr]] = Field(default=None, description="The case(s) to whom the product is tied. **IMPORTANT:** This field cannot be updated directly, only through the protection_product/case APIs.")
    org_provider_reference: Optional[StrictStr] = Field(default=None, description="Reference to an Acre Org that is the provider.")
    source: Optional[CdmProtectionSource] = None
    modified_at: Optional[StrictStr] = None
    solution_type: Optional[ProtectionProductDetailsSolutionType] = ProtectionProductDetailsSolutionType.INVALID_SOLUTION_TYPE
    product_benefit_group_id: Optional[StrictStr] = Field(default=None, description="Id of Product Benefit Group that the product belongs to (created by protection-service).")
    product_benefits: Optional[CdmProtectionProductBenefits] = None
    commission: Optional[CdmProtectionCommission] = None
    documents: Optional[CdmProtectionProductDocuments] = None
    solution_products: Optional[List[StrictStr]] = Field(default=None, description="The protection_ids of products belonging to the same solution.")
    cancellation_date: Optional[StrictStr] = Field(default=None, description="The cancellation date of the protection product (YYYY-MM-DD).")
    external: Optional[List[CdmExternal]] = Field(default=None, description="Identifiers for the protection product in third-party systems.")
    not_proceeding_details: Optional[CdmProtectionProductNotProceeding] = None
    __properties: ClassVar[List[str]] = ["protection_id", "provider_name", "premium_frequency", "product_name", "recommendation_premium_amount", "underwritten_premium_amount", "product_details", "policy_number", "start_date", "end_date", "source_response", "is_employment_benefit", "keep_existing_policy", "product_recommendation_justification", "status", "client_ids", "case_ids", "org_provider_reference", "source", "modified_at", "solution_type", "product_benefit_group_id", "product_benefits", "commission", "documents", "solution_products", "cancellation_date", "external", "not_proceeding_details"]

    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 CdmProtectionProductDetails 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,
        )
        # override the default output from pydantic by calling `to_dict()` of source
        if self.source:
            _dict['source'] = self.source.to_dict()
        # override the default output from pydantic by calling `to_dict()` of product_benefits
        if self.product_benefits:
            _dict['product_benefits'] = self.product_benefits.to_dict()
        # override the default output from pydantic by calling `to_dict()` of commission
        if self.commission:
            _dict['commission'] = self.commission.to_dict()
        # override the default output from pydantic by calling `to_dict()` of documents
        if self.documents:
            _dict['documents'] = self.documents.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in external (list)
        _items = []
        if self.external:
            for _item_external in self.external:
                if _item_external:
                    _items.append(_item_external.to_dict())
            _dict['external'] = _items
        # override the default output from pydantic by calling `to_dict()` of not_proceeding_details
        if self.not_proceeding_details:
            _dict['not_proceeding_details'] = self.not_proceeding_details.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "protection_id": obj.get("protection_id"),
            "provider_name": obj.get("provider_name"),
            "premium_frequency": obj.get("premium_frequency") if obj.get("premium_frequency") is not None else CdmPremiumFrequency.INVALID_PREMIUM_FREQUENCY,
            "product_name": obj.get("product_name"),
            "recommendation_premium_amount": obj.get("recommendation_premium_amount"),
            "underwritten_premium_amount": obj.get("underwritten_premium_amount"),
            "product_details": obj.get("product_details"),
            "policy_number": obj.get("policy_number"),
            "start_date": obj.get("start_date"),
            "end_date": obj.get("end_date"),
            "source_response": obj.get("source_response"),
            "is_employment_benefit": obj.get("is_employment_benefit"),
            "keep_existing_policy": obj.get("keep_existing_policy"),
            "product_recommendation_justification": obj.get("product_recommendation_justification"),
            "status": obj.get("status") if obj.get("status") is not None else CdmProtectionProductDetailsStatus.INVALID_STATUS,
            "client_ids": obj.get("client_ids"),
            "case_ids": obj.get("case_ids"),
            "org_provider_reference": obj.get("org_provider_reference"),
            "source": CdmProtectionSource.from_dict(obj["source"]) if obj.get("source") is not None else None,
            "modified_at": obj.get("modified_at"),
            "solution_type": obj.get("solution_type") if obj.get("solution_type") is not None else ProtectionProductDetailsSolutionType.INVALID_SOLUTION_TYPE,
            "product_benefit_group_id": obj.get("product_benefit_group_id"),
            "product_benefits": CdmProtectionProductBenefits.from_dict(obj["product_benefits"]) if obj.get("product_benefits") is not None else None,
            "commission": CdmProtectionCommission.from_dict(obj["commission"]) if obj.get("commission") is not None else None,
            "documents": CdmProtectionProductDocuments.from_dict(obj["documents"]) if obj.get("documents") is not None else None,
            "solution_products": obj.get("solution_products"),
            "cancellation_date": obj.get("cancellation_date"),
            "external": [CdmExternal.from_dict(_item) for _item in obj["external"]] if obj.get("external") is not None else None,
            "not_proceeding_details": CdmProtectionProductNotProceeding.from_dict(obj["not_proceeding_details"]) if obj.get("not_proceeding_details") is not None else None
        })
        return _obj


