# 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

class Group(BaseModel):
    """
    Class representing a group returned by the web service API.
    """
    cancelled: Optional[StrictBool] = Field(None, description="Flag indicating if the group is cancelled.")
    groupid: Optional[StrictStr] = Field(None, description="The group's numeric ID (actually a string e.g., \"100656\").")
    name: Optional[StrictStr] = Field(None, description="The group's unique name (e.g., \"cs-editors\").")
    title: Optional[StrictStr] = Field(None, description="The group's title.")
    description: Optional[StrictStr] = Field(None, description="The more detailed description of the group.")
    email: Optional[StrictStr] = Field(None, description="The group's email address.")
    members_of_inst: Optional[GroupMembersOfInst] = Field(None, alias="membersOfInst")
    members: Optional[conlist(Person)] = Field(None, description="A list of the group's members, including (recursively) any members of any included groups. This will only be populated if the `fetch` parameter includes the `\"all_members\"` option.")
    direct_members: Optional[conlist(Person)] = Field(None, alias="directMembers", description="A list of the group's direct members, not including any members included via groups included by this group. This will only be populated if the `fetch` parameter includes the `\"direct_members\"` option.")
    owning_insts: Optional[conlist(Institution)] = Field(None, alias="owningInsts", description="A list of the institutions to which this group belongs. This will only be populated if the `fetch` parameter includes the `\"owning_insts\"` option.")
    manages_insts: Optional[conlist(Institution)] = Field(None, alias="managesInsts", description="A list of the institutions managed by this group. This will only be populated if the `fetch` parameter includes the `\"manages_insts\"` option.")
    manages_groups: Optional[conlist(Group)] = Field(None, alias="managesGroups", description="A list of the groups managed by this group. This will only be populated if the `fetch` parameter includes the `\"manages_groups\"` option.")
    managed_by_groups: Optional[conlist(Group)] = Field(None, alias="managedByGroups", description="A list of the groups that manage this group. This will only be populated if the `fetch` parameter includes the `\"managed_by_groups\"` option.")
    reads_groups: Optional[conlist(Group)] = Field(None, alias="readsGroups", description="A list of the groups that this group has privileged access to. Members of this group will be able to read the members of any of those groups, regardless of the membership visibilities. This will only be populated if the `fetch` parameter includes the `\"reads_groups\"` option.")
    read_by_groups: Optional[conlist(Group)] = Field(None, alias="readByGroups", description="A list of the groups that have privileged access to this group. Members of those groups will be able to read the members of this group, regardless of the membership visibilities. This will only be populated if the `fetch` parameter includes the `\"read_by_groups\"` option.")
    includes_groups: Optional[conlist(Group)] = Field(None, alias="includesGroups", description="A list of the groups directly included in this group. Any members of the included groups (and recursively any groups that they include) will automatically be included in this group. This will only be populated if the `fetch` parameter includes the `\"includes_groups\"` option.")
    included_by_groups: Optional[conlist(Group)] = Field(None, alias="includedByGroups", description="A list of the groups that directly include this group. Any members of this group will automatically be included in those groups (and recursively in any groups that include those groups). This will only be populated if the `fetch` parameter includes the `\"included_by_groups\"` option.")
    id: Optional[StrictStr] = Field(None, description="An ID that can uniquely identify this group 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 group element in the XML/JSON document. This is only used in the flattened XML/JSON representation (if the \"flatten\" parameter is specified).")
    __properties = ["cancelled", "groupid", "name", "title", "description", "email", "membersOfInst", "members", "directMembers", "owningInsts", "managesInsts", "managesGroups", "managedByGroups", "readsGroups", "readByGroups", "includesGroups", "includedByGroups", "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) -> Group:
        """Create an instance of Group 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 members_of_inst
        if self.members_of_inst:
            _dict['membersOfInst'] = self.members_of_inst.to_dict()
        # 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 direct_members (list)
        _items = []
        if self.direct_members:
            for _item in self.direct_members:
                if _item:
                    _items.append(_item.to_dict())
            _dict['directMembers'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in owning_insts (list)
        _items = []
        if self.owning_insts:
            for _item in self.owning_insts:
                if _item:
                    _items.append(_item.to_dict())
            _dict['owningInsts'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in manages_insts (list)
        _items = []
        if self.manages_insts:
            for _item in self.manages_insts:
                if _item:
                    _items.append(_item.to_dict())
            _dict['managesInsts'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in manages_groups (list)
        _items = []
        if self.manages_groups:
            for _item in self.manages_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['managesGroups'] = _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
        # override the default output from pydantic by calling `to_dict()` of each item in reads_groups (list)
        _items = []
        if self.reads_groups:
            for _item in self.reads_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['readsGroups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in read_by_groups (list)
        _items = []
        if self.read_by_groups:
            for _item in self.read_by_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['readByGroups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in includes_groups (list)
        _items = []
        if self.includes_groups:
            for _item in self.includes_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['includesGroups'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in included_by_groups (list)
        _items = []
        if self.included_by_groups:
            for _item in self.included_by_groups:
                if _item:
                    _items.append(_item.to_dict())
            _dict['includedByGroups'] = _items
        return _dict

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

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

        _obj = Group.parse_obj({
            "cancelled": obj.get("cancelled"),
            "groupid": obj.get("groupid"),
            "name": obj.get("name"),
            "title": obj.get("title"),
            "description": obj.get("description"),
            "email": obj.get("email"),
            "members_of_inst": GroupMembersOfInst.from_dict(obj.get("membersOfInst")) if obj.get("membersOfInst") 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,
            "direct_members": [Person.from_dict(_item) for _item in obj.get("directMembers")] if obj.get("directMembers") is not None else None,
            "owning_insts": [Institution.from_dict(_item) for _item in obj.get("owningInsts")] if obj.get("owningInsts") is not None else None,
            "manages_insts": [Institution.from_dict(_item) for _item in obj.get("managesInsts")] if obj.get("managesInsts") is not None else None,
            "manages_groups": [Group.from_dict(_item) for _item in obj.get("managesGroups")] if obj.get("managesGroups") 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,
            "reads_groups": [Group.from_dict(_item) for _item in obj.get("readsGroups")] if obj.get("readsGroups") is not None else None,
            "read_by_groups": [Group.from_dict(_item) for _item in obj.get("readByGroups")] if obj.get("readByGroups") is not None else None,
            "includes_groups": [Group.from_dict(_item) for _item in obj.get("includesGroups")] if obj.get("includesGroups") is not None else None,
            "included_by_groups": [Group.from_dict(_item) for _item in obj.get("includedByGroups")] if obj.get("includedByGroups") is not None else None,
            "id": obj.get("id"),
            "ref": obj.get("ref")
        })
        return _obj

from identitylib.lookup_client.models.group_members_of_inst import GroupMembersOfInst
from identitylib.lookup_client.models.institution import Institution
from identitylib.lookup_client.models.person import Person
Group.update_forward_refs()

