# coding: utf-8

"""
    CATAPA API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.0.0
    Contact: support@catapa.com
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from openapi_client.models.additional_family_membership_response import AdditionalFamilyMembershipResponse
from openapi_client.models.bpjs_healthcare_provider_list_item_response import BpjsHealthcareProviderListItemResponse
from openapi_client.models.bpjs_healthcare_template_list_item_response import BpjsHealthcareTemplateListItemResponse
from openapi_client.models.bpjs_healthcare_treatment_class_response import BpjsHealthcareTreatmentClassResponse
from typing import Optional, Set
from typing_extensions import Self

class BpjsHealthcareMembershipResponse(BaseModel):
    """
    BpjsHealthcareMembershipResponse
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, description="ID of the BPJS Healthcare Membership")
    employee_id: Optional[StrictStr] = Field(default=None, alias="employeeId")
    membership_number: Optional[StrictStr] = Field(default=None, alias="membershipNumber")
    start_date: Optional[StrictStr] = Field(default=None, alias="startDate")
    end_date: Optional[StrictStr] = Field(default=None, alias="endDate")
    effective_date: Optional[StrictStr] = Field(default=None, alias="effectiveDate")
    first_level_healthcare_facility: Optional[StrictStr] = Field(default=None, alias="firstLevelHealthcareFacility")
    dental_healthcare_facility: Optional[StrictStr] = Field(default=None, alias="dentalHealthcareFacility")
    bpjs_healthcare_provider: Optional[BpjsHealthcareProviderListItemResponse] = Field(default=None, alias="bpjsHealthcareProvider")
    bpjs_healthcare_template: Optional[BpjsHealthcareTemplateListItemResponse] = Field(default=None, alias="bpjsHealthcareTemplate")
    bpjs_healthcare_treatment_class: Optional[BpjsHealthcareTreatmentClassResponse] = Field(default=None, alias="bpjsHealthcareTreatmentClass")
    additional_family_memberships: Optional[List[AdditionalFamilyMembershipResponse]] = Field(default=None, alias="additionalFamilyMemberships")
    __properties: ClassVar[List[str]] = ["id", "employeeId", "membershipNumber", "startDate", "endDate", "effectiveDate", "firstLevelHealthcareFacility", "dentalHealthcareFacility", "bpjsHealthcareProvider", "bpjsHealthcareTemplate", "bpjsHealthcareTreatmentClass", "additionalFamilyMemberships"]

    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 BpjsHealthcareMembershipResponse 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 bpjs_healthcare_provider
        if self.bpjs_healthcare_provider:
            _dict['bpjsHealthcareProvider'] = self.bpjs_healthcare_provider.to_dict()
        # override the default output from pydantic by calling `to_dict()` of bpjs_healthcare_template
        if self.bpjs_healthcare_template:
            _dict['bpjsHealthcareTemplate'] = self.bpjs_healthcare_template.to_dict()
        # override the default output from pydantic by calling `to_dict()` of bpjs_healthcare_treatment_class
        if self.bpjs_healthcare_treatment_class:
            _dict['bpjsHealthcareTreatmentClass'] = self.bpjs_healthcare_treatment_class.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in additional_family_memberships (list)
        _items = []
        if self.additional_family_memberships:
            for _item_additional_family_memberships in self.additional_family_memberships:
                if _item_additional_family_memberships:
                    _items.append(_item_additional_family_memberships.to_dict())
            _dict['additionalFamilyMemberships'] = _items
        # set to None if end_date (nullable) is None
        # and model_fields_set contains the field
        if self.end_date is None and "end_date" in self.model_fields_set:
            _dict['endDate'] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of BpjsHealthcareMembershipResponse 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"),
            "employeeId": obj.get("employeeId"),
            "membershipNumber": obj.get("membershipNumber"),
            "startDate": obj.get("startDate"),
            "endDate": obj.get("endDate"),
            "effectiveDate": obj.get("effectiveDate"),
            "firstLevelHealthcareFacility": obj.get("firstLevelHealthcareFacility"),
            "dentalHealthcareFacility": obj.get("dentalHealthcareFacility"),
            "bpjsHealthcareProvider": BpjsHealthcareProviderListItemResponse.from_dict(obj["bpjsHealthcareProvider"]) if obj.get("bpjsHealthcareProvider") is not None else None,
            "bpjsHealthcareTemplate": BpjsHealthcareTemplateListItemResponse.from_dict(obj["bpjsHealthcareTemplate"]) if obj.get("bpjsHealthcareTemplate") is not None else None,
            "bpjsHealthcareTreatmentClass": BpjsHealthcareTreatmentClassResponse.from_dict(obj["bpjsHealthcareTreatmentClass"]) if obj.get("bpjsHealthcareTreatmentClass") is not None else None,
            "additionalFamilyMemberships": [AdditionalFamilyMembershipResponse.from_dict(_item) for _item in obj["additionalFamilyMemberships"]] if obj.get("additionalFamilyMemberships") is not None else None
        })
        return _obj


