# coding: utf-8

"""
    University Student API

    This API exposes identity information about university students. The purpose of this API is to give access to basic identity information about university students for use by downstream systems, therefore the data exposed is limited to basic information about who a student is and which institutions they are affiliated with.  This API uses the following identifiers to link people to person-records held within different systems:  * `person.v1.student-records.university.identifiers.cam.ac.uk` - the university student (ust) identifier of this person -   also referred to as USN  Additionally this API uses the following identifiers to link people to institutions or entities which a person may have an affiliation to:  * `institution.v1.student-records.university.identifiers.cam.ac.uk` - the university student (ust) institution identifier.     This encompasses colleges, departments and faculties. The     [CamSIS Coding Manual](https://www.camsis.cam.ac.uk/technical/camsis-coding-manual)     lists the available values for this affiliation (under A01 and M01). * `academic-plan.v1.student-records.university.identifiers.cam.ac.uk` - the university student (ust) academic plan     identifier. The     [CamSIS Coding Manual](https://www.camsis.cam.ac.uk/technical/camsis-coding-manual)     lists the available values for this affiliation (under D07).  Both affiliations provide a `status` field which indicate a student's status within an affiliated entity. This `status` field is the short representation of the academic career field held in CamSIS. The [CamSIS Coding Manual](https://www.camsis.cam.ac.uk/technical/camsis-coding-manual) lists the available values for the `status` field (under D05).  This API is currently backed by data from CamSIS, exposing a view of data that is refreshed nightly.  

    The version of the OpenAPI document: v1alpha2
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


import re  # noqa: F401
import io
import warnings

from pydantic import validate_arguments, ValidationError
from typing_extensions import Annotated

from pydantic import Field, StrictStr

from typing import Optional

from identitylib.student_client.models.paginated_results_student import PaginatedResultsStudent
from identitylib.student_client.models.student import Student

from identitylib.student_client.api_client import ApiClient
from identitylib.student_client.api_response import ApiResponse
from identitylib.student_client.exceptions import (  # noqa: F401
    ApiTypeError,
    ApiValueError
)


class StudentsApi(object):
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient.get_default()
        self.api_client = api_client

    @validate_arguments
    def get_v1alpha2_student_students_identifier_get(self, identifier : StrictStr, **kwargs) -> Student:  # noqa: E501
        """Get a single student  # noqa: E501

        Returns a single student based on the identifier provided. The identifier can be provided in the format `<value>@<scheme>`, if the scheme is omitted it shall be assumed that the scheme is `person.v1.student-records.university.identifiers.cam.ac.uk` (also know as the USN).   Currently this endpoint only supports querying by `person.v1.student-records.university.identifiers.cam.ac.uk` identifiers, but may be extended to allow querying by additional identifier schemes in future.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.get_v1alpha2_student_students_identifier_get(identifier, async_req=True)
        >>> result = thread.get()

        :param identifier: (required)
        :type identifier: str
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: Student
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            raise ValueError("Error! Please call the get_v1alpha2_student_students_identifier_get_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data")
        return self.get_v1alpha2_student_students_identifier_get_with_http_info(identifier, **kwargs)  # noqa: E501

    @validate_arguments
    def get_v1alpha2_student_students_identifier_get_with_http_info(self, identifier : StrictStr, **kwargs) -> ApiResponse:  # noqa: E501
        """Get a single student  # noqa: E501

        Returns a single student based on the identifier provided. The identifier can be provided in the format `<value>@<scheme>`, if the scheme is omitted it shall be assumed that the scheme is `person.v1.student-records.university.identifiers.cam.ac.uk` (also know as the USN).   Currently this endpoint only supports querying by `person.v1.student-records.university.identifiers.cam.ac.uk` identifiers, but may be extended to allow querying by additional identifier schemes in future.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.get_v1alpha2_student_students_identifier_get_with_http_info(identifier, async_req=True)
        >>> result = thread.get()

        :param identifier: (required)
        :type identifier: str
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the 
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(Student, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'identifier'
        ]
        _all_params.extend(
            [
                'async_req',
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_v1alpha2_student_students_identifier_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}
        if _params['identifier']:
            _path_params['identifier'] = _params['identifier']


        # process the query parameters
        _query_params = []
        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['ApiGatewayOAuthClientCredentials']  # noqa: E501

        _response_types_map = {
            '200': "Student",
            '400': "HTTPException",
            '404': "HTTPException",
            '422': "HTTPValidationError",
        }

        return self.api_client.call_api(
            '/students/{identifier}', 'GET',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            async_req=_params.get('async_req'),
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    def list_v1alpha2_recent_graduates_recent_graduates_get(self, affiliation : Annotated[Optional[StrictStr], Field(description="An affiliation to filter by, in the format `<value>@<scheme>`. When included only graduates with a matching affiliation are returned.")] = None, cursor : Annotated[Optional[StrictStr], Field(description="The cursor indicating a unique page of results - this should be auto generated on the `next` and `previous` fields and does not need to be manually added / updated.")] = None, **kwargs) -> PaginatedResultsStudent:  # noqa: E501
        """List students who have completed a course within the last six months  # noqa: E501

        Returns students who have ended their affiliation with an institution or academic plan within the last six months, indicating that they have recently completed their studies. This is to allow downstream systems access to data on students who may in-practice continue to have an affiliation with the University, even though their course has technically ended.  Affiliations populated on each recent graduate are limited to the affiliations which have ended within the last six months. Graduates may have additional affiliations which are not represented here. These affiliations can be accessed by querying the `/students` endpoint.  Students who have either been removed or withdrawn from a course are not returned.  To avoid returning very large responses, this endpoint produces a paged response. Where there are additional results which cannot be returned on a single page, a `next` field will be populated with a url containing the next page of results. These `next` urls should be followed until a page is returned with no `next` field, indicating that there are no further results. Each page returned will hold a maximum of 1000 results.  Graduates can be filtered by affiliation, by providing an `affiliation` query parameter. This affiliation should be provided in the format `<value>@<scheme>`. Graduates will only be returned if their affiliation with an institution or academic plan has ended within the last six months.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.list_v1alpha2_recent_graduates_recent_graduates_get(affiliation, cursor, async_req=True)
        >>> result = thread.get()

        :param affiliation: An affiliation to filter by, in the format `<value>@<scheme>`. When included only graduates with a matching affiliation are returned.
        :type affiliation: str
        :param cursor: The cursor indicating a unique page of results - this should be auto generated on the `next` and `previous` fields and does not need to be manually added / updated.
        :type cursor: str
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: PaginatedResultsStudent
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            raise ValueError("Error! Please call the list_v1alpha2_recent_graduates_recent_graduates_get_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data")
        return self.list_v1alpha2_recent_graduates_recent_graduates_get_with_http_info(affiliation, cursor, **kwargs)  # noqa: E501

    @validate_arguments
    def list_v1alpha2_recent_graduates_recent_graduates_get_with_http_info(self, affiliation : Annotated[Optional[StrictStr], Field(description="An affiliation to filter by, in the format `<value>@<scheme>`. When included only graduates with a matching affiliation are returned.")] = None, cursor : Annotated[Optional[StrictStr], Field(description="The cursor indicating a unique page of results - this should be auto generated on the `next` and `previous` fields and does not need to be manually added / updated.")] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """List students who have completed a course within the last six months  # noqa: E501

        Returns students who have ended their affiliation with an institution or academic plan within the last six months, indicating that they have recently completed their studies. This is to allow downstream systems access to data on students who may in-practice continue to have an affiliation with the University, even though their course has technically ended.  Affiliations populated on each recent graduate are limited to the affiliations which have ended within the last six months. Graduates may have additional affiliations which are not represented here. These affiliations can be accessed by querying the `/students` endpoint.  Students who have either been removed or withdrawn from a course are not returned.  To avoid returning very large responses, this endpoint produces a paged response. Where there are additional results which cannot be returned on a single page, a `next` field will be populated with a url containing the next page of results. These `next` urls should be followed until a page is returned with no `next` field, indicating that there are no further results. Each page returned will hold a maximum of 1000 results.  Graduates can be filtered by affiliation, by providing an `affiliation` query parameter. This affiliation should be provided in the format `<value>@<scheme>`. Graduates will only be returned if their affiliation with an institution or academic plan has ended within the last six months.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.list_v1alpha2_recent_graduates_recent_graduates_get_with_http_info(affiliation, cursor, async_req=True)
        >>> result = thread.get()

        :param affiliation: An affiliation to filter by, in the format `<value>@<scheme>`. When included only graduates with a matching affiliation are returned.
        :type affiliation: str
        :param cursor: The cursor indicating a unique page of results - this should be auto generated on the `next` and `previous` fields and does not need to be manually added / updated.
        :type cursor: str
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the 
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(PaginatedResultsStudent, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'affiliation',
            'cursor'
        ]
        _all_params.extend(
            [
                'async_req',
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method list_v1alpha2_recent_graduates_recent_graduates_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}

        # process the query parameters
        _query_params = []
        if _params.get('affiliation') is not None:  # noqa: E501
            _query_params.append(('affiliation', _params['affiliation']))

        if _params.get('cursor') is not None:  # noqa: E501
            _query_params.append(('cursor', _params['cursor']))

        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['ApiGatewayOAuthClientCredentials']  # noqa: E501

        _response_types_map = {
            '200': "PaginatedResultsStudent",
            '400': "HTTPException",
            '422': "HTTPValidationError",
        }

        return self.api_client.call_api(
            '/recent-graduates', 'GET',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            async_req=_params.get('async_req'),
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))

    @validate_arguments
    def list_v1alpha2_students_students_get(self, affiliation : Annotated[Optional[StrictStr], Field(description="An affiliation to filter by, in the format `<value>@<scheme>`. When included only the students with a matching affiliation are returned.")] = None, cursor : Annotated[Optional[StrictStr], Field(description="The cursor indicating a unique page of results - this should be auto generated on the `next` and `previous` fields and does not need to be manually added / updated.")] = None, **kwargs) -> PaginatedResultsStudent:  # noqa: E501
        """List students  # noqa: E501

        Lists all students held within the University Student management system, allowing basic filtering by affiliation.  To avoid returning very large responses, this endpoint produces a paged response. Where there are additional results which cannot be returned on a single page, a `next` field will be populated with a url containing the next page of results. These `next` urls should be followed until a page is returned with no `next` field, indicating that there are no further results. Each page returned will hold a maximum of 1000 results.  Students can be filtered by affiliation, by providing an `affiliation` query parameter. This affiliation should be provided in the format `<value>@<scheme>`.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.list_v1alpha2_students_students_get(affiliation, cursor, async_req=True)
        >>> result = thread.get()

        :param affiliation: An affiliation to filter by, in the format `<value>@<scheme>`. When included only the students with a matching affiliation are returned.
        :type affiliation: str
        :param cursor: The cursor indicating a unique page of results - this should be auto generated on the `next` and `previous` fields and does not need to be manually added / updated.
        :type cursor: str
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: PaginatedResultsStudent
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            raise ValueError("Error! Please call the list_v1alpha2_students_students_get_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data")
        return self.list_v1alpha2_students_students_get_with_http_info(affiliation, cursor, **kwargs)  # noqa: E501

    @validate_arguments
    def list_v1alpha2_students_students_get_with_http_info(self, affiliation : Annotated[Optional[StrictStr], Field(description="An affiliation to filter by, in the format `<value>@<scheme>`. When included only the students with a matching affiliation are returned.")] = None, cursor : Annotated[Optional[StrictStr], Field(description="The cursor indicating a unique page of results - this should be auto generated on the `next` and `previous` fields and does not need to be manually added / updated.")] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """List students  # noqa: E501

        Lists all students held within the University Student management system, allowing basic filtering by affiliation.  To avoid returning very large responses, this endpoint produces a paged response. Where there are additional results which cannot be returned on a single page, a `next` field will be populated with a url containing the next page of results. These `next` urls should be followed until a page is returned with no `next` field, indicating that there are no further results. Each page returned will hold a maximum of 1000 results.  Students can be filtered by affiliation, by providing an `affiliation` query parameter. This affiliation should be provided in the format `<value>@<scheme>`.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.list_v1alpha2_students_students_get_with_http_info(affiliation, cursor, async_req=True)
        >>> result = thread.get()

        :param affiliation: An affiliation to filter by, in the format `<value>@<scheme>`. When included only the students with a matching affiliation are returned.
        :type affiliation: str
        :param cursor: The cursor indicating a unique page of results - this should be auto generated on the `next` and `previous` fields and does not need to be manually added / updated.
        :type cursor: str
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the 
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(PaginatedResultsStudent, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'affiliation',
            'cursor'
        ]
        _all_params.extend(
            [
                'async_req',
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method list_v1alpha2_students_students_get" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}

        # process the query parameters
        _query_params = []
        if _params.get('affiliation') is not None:  # noqa: E501
            _query_params.append(('affiliation', _params['affiliation']))

        if _params.get('cursor') is not None:  # noqa: E501
            _query_params.append(('cursor', _params['cursor']))

        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['ApiGatewayOAuthClientCredentials']  # noqa: E501

        _response_types_map = {
            '200': "PaginatedResultsStudent",
            '400': "HTTPException",
            '422': "HTTPValidationError",
        }

        return self.api_client.call_api(
            '/students', 'GET',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            async_req=_params.get('async_req'),
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))
