# coding: utf-8

"""
    Lookup/Ibis web service API

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

    The version of the OpenAPI document: 1.2
    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 typing import List, Optional
from pydantic import BaseModel, Field, StrictBool, StrictStr, conlist
from identitylib.lookup_client.models.attribute import Attribute
from identitylib.lookup_client.models.identifier import Identifier
from identitylib.lookup_client.models.person_identifier import PersonIdentifier

class Person(BaseModel):
    """
    Class representing a person returned by the web service API. Note that the identifier is the person's primary identifier (typically their CRSid), regardless of which identifier was used to query for the person.
    """
    cancelled: Optional[StrictBool] = Field(None, description="Flag indicating if the person is cancelled.")
    identifier: Optional[PersonIdentifier] = None
    display_name: Optional[StrictStr] = Field(None, alias="displayName", description="The person's display name (if visible).")
    registered_name: Optional[StrictStr] = Field(None, alias="registeredName", description="The person's registered name (if visible).")
    surname: Optional[StrictStr] = Field(None, description="The person's surname (if visible).")
    visible_name: Optional[StrictStr] = Field(None, alias="visibleName", description="The person's display name if that is visible, otherwise their registered name if that is visible, otherwise their surname if that is visible, otherwise the value of their primary identifier (typically their CRSid) which is always visible.")
    mis_affiliation: Optional[StrictStr] = Field(None, alias="misAffiliation", description="The person's MIS status (`\"staff\"`, `\"student\"`, `\"staff,student\"` or `\"\"`).")
    identifiers: Optional[conlist(Identifier)] = Field(None, description="A list of the person's identifiers. This will only be populated if the `fetch` parameter included the `\"all_identifiers\"` option.")
    attributes: Optional[conlist(Attribute)] = Field(None, description="A list of the person's attributes. This will only be populated if the `fetch` parameter includes the `\"all_attrs\"` option, or any specific attribute schemes such as `\"email\"` or `\"title\"`, or the special pseudo-attribute scheme `\"phone_numbers\"`.")
    institutions: Optional[conlist(Institution)] = Field(None, description="A list of all the institution's to which the person belongs. This will only be populated if the `fetch` parameter includes the `\"all_insts\"` option.")
    groups: Optional[conlist(Group)] = Field(None, description="A list of all the groups to which the person belongs, including indirect group memberships, via groups that include other groups. This will only be populated if the `fetch` parameter includes the `\"all_groups\"` option.")
    direct_groups: Optional[conlist(Group)] = Field(None, alias="directGroups", description="A list of all the groups that the person directly belongs to. This does not include indirect group memberships - i.e., groups that include these groups. This will only be populated if the `fetch` parameter includes the `\"direct_groups\"` option.")
    id: Optional[StrictStr] = Field(None, description="An ID that can uniquely identify this person within the returned XML/JSON document. This is only used in the flattened XML/JSON representation (if the \"flatten\" parameter is specified).")
    ref: Optional[StrictStr] = Field(None, description="A reference (by id) to a person element in the XML/JSON document. This is only used in the flattened XML/JSON representation (if the \"flatten\" parameter is specified).")
    __properties = ["cancelled", "identifier", "displayName", "registeredName", "surname", "visibleName", "misAffiliation", "identifiers", "attributes", "institutions", "groups", "directGroups", "id", "ref"]

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Person:
        """Create an instance of Person from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of identifier
        if self.identifier:
            _dict['identifier'] = self.identifier.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in identifiers (list)
        _items = []
        if self.identifiers:
            for _item in self.identifiers:
                if _item:
                    _items.append(_item.to_dict())
            _dict['identifiers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in attributes (list)
        _items = []
        if self.attributes:
            for _item in self.attributes:
                if _item:
                    _items.append(_item.to_dict())
            _dict['attributes'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in institutions (list)
        _items = []
        if self.institutions:
            for _item in self.institutions:
                if _item:
                    _items.append(_item.to_dict())
            _dict['institutions'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in groups (list)
        _items = []
        if self.groups:
            for _item in self.groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['groups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in direct_groups (list)
        _items = []
        if self.direct_groups:
            for _item in self.direct_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['directGroups'] = _items
        return _dict

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

        if not isinstance(obj, dict):
            return Person.parse_obj(obj)

        _obj = Person.parse_obj({
            "cancelled": obj.get("cancelled"),
            "identifier": PersonIdentifier.from_dict(obj.get("identifier")) if obj.get("identifier") is not None else None,
            "display_name": obj.get("displayName"),
            "registered_name": obj.get("registeredName"),
            "surname": obj.get("surname"),
            "visible_name": obj.get("visibleName"),
            "mis_affiliation": obj.get("misAffiliation"),
            "identifiers": [Identifier.from_dict(_item) for _item in obj.get("identifiers")] if obj.get("identifiers") is not None else None,
            "attributes": [Attribute.from_dict(_item) for _item in obj.get("attributes")] if obj.get("attributes") is not None else None,
            "institutions": [Institution.from_dict(_item) for _item in obj.get("institutions")] if obj.get("institutions") is not None else None,
            "groups": [Group.from_dict(_item) for _item in obj.get("groups")] if obj.get("groups") is not None else None,
            "direct_groups": [Group.from_dict(_item) for _item in obj.get("directGroups")] if obj.get("directGroups") is not None else None,
            "id": obj.get("id"),
            "ref": obj.get("ref")
        })
        return _obj

from identitylib.lookup_client.models.group import Group
from identitylib.lookup_client.models.institution import Institution
Person.update_forward_refs()

