# coding: utf-8

"""
    University Human Resources API

    This API exposes identity information from the University Human Resources system. The purpose of this API is to give access to basic identity information about staff members for use by downstream systems, therefore the data exposed is limited to basic information about who a staff member is and details of any affiliations they have.  This API uses the following identifiers to link people to person-records held within different systems:  * `person.v1.human-resources.university.identifiers.cam.ac.uk` - the university human resources (uhr) identifier of     this person - also known as the staff number of HRN. * `v1.person.identifiers.cam.ac.uk` - the common registration scheme identifier (CRSid) of     this person.  Additionally this API uses the following identifiers to link people to institutions or entities which a person may have an affiliation to:  * `institution.v1.human-resources.university.identifiers.cam.ac.uk` - the university human resources (uhr) institution     identifier. This encompasses departments within the University HR system     (currently CHRIS). * `institution.v1.student-records.university.identifiers.cam.ac.uk` - the student records institution identifier. This     encompasses colleges within the University Student Records system (currently CamSIS).  Affiliations can be used to indicate an institution that a person holds a position within, with the `status` indicating the job role that is held and the scheme of the affiliation being `institution.v1.human-resources.university.identifiers.cam.ac.uk`. Additionally an affiliation can indicate a staff member's line manager with the scheme being `person.v1.human-resources.university.identifiers.cam.ac.uk` and the status being `report`. A staff member can have multiple institution affiliations and multiple report affiliations.  This API is currently backed by data from CHRIS, exposing a view which is updated hourly.  

    The version of the OpenAPI document: v1alpha2
    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 datetime import date
from typing import Optional
from pydantic import BaseModel, Field, StrictStr
from identitylib.hr_client.models.affiliation_scheme import AffiliationScheme

class Affiliation(BaseModel):
    """
    A representation of an affiliation - indicating what type of affiliation this is and the entity which the affiliation is related to. Also contains a `status` indicating the position of this staff member in relation to the affiliated entity.
    """
    end: Optional[date] = Field(None, description="The end date of this affiliation. May not be populated if the affiliation is open-ended.")
    scheme: AffiliationScheme = Field(...)
    start: Optional[date] = Field(None, description="The start date of this affiliation. May not be populated if not known.")
    status: StrictStr = Field(..., description="A staff member's status in relation to an affiliated entity. Currently this will be their job title or `report`, indicating that this person reports to the affiliated entity.")
    value: StrictStr = Field(..., description="The value of this affiliation. This will be specific to the human resources system, indicating an entity that this staff member is affiliated with.")
    __properties = ["end", "scheme", "start", "status", "value"]

    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) -> Affiliation:
        """Create an instance of Affiliation 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)
        # set to None if end (nullable) is None
        # and __fields_set__ contains the field
        if self.end is None and "end" in self.__fields_set__:
            _dict['end'] = None

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

        return _dict

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

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

        _obj = Affiliation.parse_obj({
            "end": obj.get("end"),
            "scheme": obj.get("scheme"),
            "start": obj.get("start"),
            "status": obj.get("status"),
            "value": obj.get("value")
        })
        return _obj


