# 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.contact_row import ContactRow
from identitylib.lookup_client.models.group import Group
from identitylib.lookup_client.models.institution import Institution
from identitylib.lookup_client.models.person import Person

class GroupMembersOfInst(BaseModel):
    """
    GroupMembersOfInst
    """
    cancelled: Optional[StrictBool] = Field(None, description="Flag indicating if the institution is cancelled.")
    instid: Optional[StrictStr] = Field(None, description="The institution's unique ID (e.g., \"CS\").")
    name: Optional[StrictStr] = Field(None, description="The institution's name.")
    acronym: Optional[StrictStr] = Field(None, description="The institution's acronym, if set (e.g., \"UCS\").")
    attributes: Optional[conlist(Attribute)] = Field(None, description="A list of the institution'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 `\"address\"`, or the special pseudo-attribute scheme `\"phone_numbers\"`.")
    contact_rows: Optional[conlist(ContactRow)] = Field(None, alias="contactRows", description="A list of the institution's contact rows. This will only be populated if the `fetch` parameter includes the `\"contact_rows\"` option.")
    members: Optional[conlist(Person)] = Field(None, description="A list of the institution's members. This will only be populated if the `fetch` parameter includes the `\"all_members\"` option.")
    parent_insts: Optional[conlist(Institution)] = Field(None, alias="parentInsts", description="A list of the institution's parent institutions. This will only be populated if the `fetch` parameter includes the `\"parent_insts\"` option.  NOTE: Currently all institutions have one parent, but in the future institutions may have multiple parents.")
    child_insts: Optional[conlist(Institution)] = Field(None, alias="childInsts", description="A list of the institution's child institutions. This will only be populated if the `fetch` parameter includes the `\"child_insts\"` option.")
    groups: Optional[conlist(Group)] = Field(None, description="A list of all the groups that belong to the institution. This will only be populated if the `fetch` parameter includes the `\"inst_groups\"` option.")
    members_groups: Optional[conlist(Group)] = Field(None, alias="membersGroups", description="A list of the groups that form the institution's membership. This will only be populated if the `fetch` parameter includes the `\"members_groups\"` option.")
    managed_by_groups: Optional[conlist(Group)] = Field(None, alias="managedByGroups", description="A list of the groups that manage this institution. This will only be populated if the `fetch` parameter includes the `\"managed_by_groups\"` option.")
    id: Optional[StrictStr] = Field(None, description="An ID that can uniquely identify this institution 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 an institution element in the XML/JSON document. This is only used in the flattened XML/JSON representation (if the \"flatten\" parameter is specified).")
    __properties = ["cancelled", "instid", "name", "acronym", "attributes", "contactRows", "members", "parentInsts", "childInsts", "groups", "membersGroups", "managedByGroups", "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) -> GroupMembersOfInst:
        """Create an instance of GroupMembersOfInst 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 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 contact_rows (list)
        _items = []
        if self.contact_rows:
            for _item in self.contact_rows:
                if _item:
                    _items.append(_item.to_dict())
            _dict['contactRows'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in members (list)
        _items = []
        if self.members:
            for _item in self.members:
                if _item:
                    _items.append(_item.to_dict())
            _dict['members'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in parent_insts (list)
        _items = []
        if self.parent_insts:
            for _item in self.parent_insts:
                if _item:
                    _items.append(_item.to_dict())
            _dict['parentInsts'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in child_insts (list)
        _items = []
        if self.child_insts:
            for _item in self.child_insts:
                if _item:
                    _items.append(_item.to_dict())
            _dict['childInsts'] = _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 members_groups (list)
        _items = []
        if self.members_groups:
            for _item in self.members_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['membersGroups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in managed_by_groups (list)
        _items = []
        if self.managed_by_groups:
            for _item in self.managed_by_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['managedByGroups'] = _items
        return _dict

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

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

        _obj = GroupMembersOfInst.parse_obj({
            "cancelled": obj.get("cancelled"),
            "instid": obj.get("instid"),
            "name": obj.get("name"),
            "acronym": obj.get("acronym"),
            "attributes": [Attribute.from_dict(_item) for _item in obj.get("attributes")] if obj.get("attributes") is not None else None,
            "contact_rows": [ContactRow.from_dict(_item) for _item in obj.get("contactRows")] if obj.get("contactRows") is not None else None,
            "members": [Person.from_dict(_item) for _item in obj.get("members")] if obj.get("members") is not None else None,
            "parent_insts": [Institution.from_dict(_item) for _item in obj.get("parentInsts")] if obj.get("parentInsts") is not None else None,
            "child_insts": [Institution.from_dict(_item) for _item in obj.get("childInsts")] if obj.get("childInsts") 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,
            "members_groups": [Group.from_dict(_item) for _item in obj.get("membersGroups")] if obj.get("membersGroups") is not None else None,
            "managed_by_groups": [Group.from_dict(_item) for _item in obj.get("managedByGroups")] if obj.get("managedByGroups") is not None else None,
            "id": obj.get("id"),
            "ref": obj.get("ref")
        })
        return _obj

from identitylib.lookup_client.models.contact_row import ContactRow
from identitylib.lookup_client.models.group import Group
from identitylib.lookup_client.models.institution import Institution
from identitylib.lookup_client.models.person import Person
GroupMembersOfInst.update_forward_refs()

