import connexion

from swagger_server.eu.dnetlib.DLIESConnector import DLIESConnector
from swagger_server.models.error import Error
from swagger_server.models.scholix import Scholix
from datetime import date, datetime
from typing import List, Dict
from six import iteritems
from ..util import deserialize_date, deserialize_datetime


def links_from_datasource_get(datasource, page=None):
    """
    Get all scholix relation collected from a datasource
    The realtionFromDatasource endpoint returns a list of scholix object collected from a specific datasource 
    :param datasource: the name of the datasource
    :type datasource: str
    :param page: The page of results
    :type page: int

    :rtype: List[Scholix]
    """
    c = DLIESConnector('ip-90-147-167-27.ct1.garrservices.it')
    p = 0
    if page:
        p = page
    return c.realtionFromDatasource(datasource, p)


def links_from_publisher_get(publisher, page=None):
    """
    Get all scholix relation collected from a publisher
    The LinksFromPublisher endpoint returns a list of scholix object collected from a specific publisher 
    :param publisher: the name of the publisher
    :type publisher: str
    :param page: The page of results
    :type page: int

    :rtype: List[Scholix]
    """
    c = DLIESConnector('ip-90-147-167-27.ct1.garrservices.it')
    p = 0
    if page:
        p = page
    return c.realtionFromPublisher(publisher, p)


def links_from_pid_get(pid, pidType=None, typologyTarget=None, datasourceTarget=None, page=None):
    """
    Retrieve all scholix links from a persistent identifier
    The linksFromPid endpoint returns a list of scholix object related from a specific persistent identifier 
    :param pid: persistent Identifier
    :type pid: str
    :param pidType: Persistent Identifier Type
    :type pidType: str
    :param typologyTarget: typology target filter should be  publication, dataset or unknown
    :type typologyTarget: str
    :param datasourceTarget: a datasource provenace filter of the target relation
    :type datasourceTarget: str
    :param page: The page of results
    :type page: int

    :rtype: List[Scholix]
    """
    c = DLIESConnector('ip-90-147-167-27.ct1.garrservices.it')
    p = 0
    if page:
        p = page
    return c.realtionToPid(pid=pid, pidType=pidType, typology=typologyTarget, datasource=datasourceTarget, page=p)
