# Path: odpw/quality/dcat_analysers.py
# def dcat_analyser():
#     dcat_analyser = {}
#     ##################### EXISTS ######################################
#     # ACCESS
# 
#     dcat_analyser['ExAc'] = AnyMetric([AccessUrlDCAT(), DownloadUrlDCAT()], id='ExAc')
#     # CONTACT
#     dcat_analyser['ExCo'] = AnyMetric([DatasetContactDCAT(), DatasetPublisherDCAT()], id='ExCo')
# 
# 
#     # DISCOVERY
#     dcat_analyser['ExDi'] = AverageMetric([DatasetTitleDCAT(), DatasetDescriptionDCAT(), DatasetKeywordsDCAT(), DistributionTitleDCAT(), DistributionDescriptionDCAT()], id='ExDi')
#     # PRESERVATION
#     dcat_analyser['ExPr'] = AverageMetric([DatasetAccrualPeriodicityDCAT(), DistributionFormatsDCAT(), DistributionMediaTypesDCAT(), DistributionByteSizeDCAT()], id='ExPr')
#     # DATE
#     dcat_analyser['ExDa'] = AverageMetric([DatasetCreationDCAT(), DatasetModificationDCAT(), DistributionIssuedDCAT(), DistributionModifiedDCAT()], id='ExDa')
# 
# 
#     # LICENSE
#     dcat_analyser['ExRi'] = ProvLicenseDCAT()
#     # TEMPORAL
#     dcat_analyser['ExTe'] = DatasetTemporalDCAT()
#     # SPATIAL
#     dcat_analyser['ExSp'] = DatasetSpatialDCAT()
# 
#     ####################### CONFORMANCE ###########################
#     # ACCESS
#     dcat_analyser['CoAc'] = AnyConformMetric([ConformAccessUrlDCAT(), ConformDownloadUrlDCAT()], id='CoAc')
#     # CONTACT
#     dcat_analyser['CoCE'] = AnyConformMetric([EmailConformContactPoint(), EmailConformPublisher()], id='CoCE')
#     dcat_analyser['CoCU'] = AnyConformMetric([UrlConformContactPoint(), UrlConformPublisher()], id='CoCU')
# 
#     # DATE
#     dcat_analyser['CoDa'] = AverageConformMetric([DateConform(dcat_access.getCreationDate),
#                                              DateConform(dcat_access.getModificationDate),
#                                              DateConform(dcat_access.getDistributionCreationDates),
#                                              DateConform(dcat_access.getDistributionModificationDates)], id='CoDa')
#     # LICENSE
#     dcat_analyser['CoLi'] = LicenseConform()
#     # FORMAT
#     dcat_analyser['CoFo'] = IANAFormatDCATAnalyser()
# 
#     ####################### OPENNESS ###########################
#     dcat_analyser['OpFo'] = FormatOpennessDCATAnalyser()
#     dcat_analyser['OpMa'] = FormatMachineReadableDCATAnalyser()
#     dcat_analyser['OpLi'] = LicenseOpennessDCATAnalyser()
# 
#     ####################### RETRIEVABILITY ###########################
#     #status_code = DatasetStatusCode()
#     #dcat_analyser['ReDa'] = status_code
#     #dcat_analyser['ReRe'] = DSRetrieveMetric(status_code)
# 
#     return dcat_analyser


from flask_restplus import reqparse
from werkzeug import datastructures
from odpw.quality.dcat_analysers import dcat_analyser

# file upload

post_param = reqparse.RequestParser()
post_param.add_argument('json_file',
                         type=datastructures.FileStorage,
                         location='files',
                         required=True,
                         help='JSON file')

# url parameter
url_param = reqparse.RequestParser()
url_param.add_argument('url', required=True, help='URL of JSON metadata document')

qual_url = reqparse.RequestParser()
qual_url.add_argument('url', required=True, help='URL of JSON metadata document')
qual_post = reqparse.RequestParser()
qual_post.add_argument('json_file',
                         type=datastructures.FileStorage,
                         location='files',
                         required=True,
                         help='JSON file')
for q in [qual_post, qual_url]:
    q.add_argument('format', required=False, choices=['json-ld', 'json', 'csv'], default='json',
                  help='Output format')

# Path: odpw/quality/dcat_analysers.py
# def dcat_analyser():
#     dcat_analyser = {}
#     ##################### EXISTS ######################################
#     # ACCESS
# 
#     dcat_analyser['ExAc'] = AnyMetric([AccessUrlDCAT(), DownloadUrlDCAT()], id='ExAc')
#     # CONTACT
#     dcat_analyser['ExCo'] = AnyMetric([DatasetContactDCAT(), DatasetPublisherDCAT()], id='ExCo')
# 
# 
#     # DISCOVERY
#     dcat_analyser['ExDi'] = AverageMetric([DatasetTitleDCAT(), DatasetDescriptionDCAT(), DatasetKeywordsDCAT(), DistributionTitleDCAT(), DistributionDescriptionDCAT()], id='ExDi')
#     # PRESERVATION
#     dcat_analyser['ExPr'] = AverageMetric([DatasetAccrualPeriodicityDCAT(), DistributionFormatsDCAT(), DistributionMediaTypesDCAT(), DistributionByteSizeDCAT()], id='ExPr')
#     # DATE
#     dcat_analyser['ExDa'] = AverageMetric([DatasetCreationDCAT(), DatasetModificationDCAT(), DistributionIssuedDCAT(), DistributionModifiedDCAT()], id='ExDa')
# 
# 
#     # LICENSE
#     dcat_analyser['ExRi'] = ProvLicenseDCAT()
#     # TEMPORAL
#     dcat_analyser['ExTe'] = DatasetTemporalDCAT()
#     # SPATIAL
#     dcat_analyser['ExSp'] = DatasetSpatialDCAT()
# 
#     ####################### CONFORMANCE ###########################
#     # ACCESS
#     dcat_analyser['CoAc'] = AnyConformMetric([ConformAccessUrlDCAT(), ConformDownloadUrlDCAT()], id='CoAc')
#     # CONTACT
#     dcat_analyser['CoCE'] = AnyConformMetric([EmailConformContactPoint(), EmailConformPublisher()], id='CoCE')
#     dcat_analyser['CoCU'] = AnyConformMetric([UrlConformContactPoint(), UrlConformPublisher()], id='CoCU')
# 
#     # DATE
#     dcat_analyser['CoDa'] = AverageConformMetric([DateConform(dcat_access.getCreationDate),
#                                              DateConform(dcat_access.getModificationDate),
#                                              DateConform(dcat_access.getDistributionCreationDates),
#                                              DateConform(dcat_access.getDistributionModificationDates)], id='CoDa')
#     # LICENSE
#     dcat_analyser['CoLi'] = LicenseConform()
#     # FORMAT
#     dcat_analyser['CoFo'] = IANAFormatDCATAnalyser()
# 
#     ####################### OPENNESS ###########################
#     dcat_analyser['OpFo'] = FormatOpennessDCATAnalyser()
#     dcat_analyser['OpMa'] = FormatMachineReadableDCATAnalyser()
#     dcat_analyser['OpLi'] = LicenseOpennessDCATAnalyser()
# 
#     ####################### RETRIEVABILITY ###########################
#     #status_code = DatasetStatusCode()
#     #dcat_analyser['ReDa'] = status_code
#     #dcat_analyser['ReRe'] = DSRetrieveMetric(status_code)
# 
#     return dcat_analyser


# Path: api/parsers.py
from flask_restplus import reqparse
from werkzeug import datastructures
from odpw.quality.dcat_analysers import dcat_analyser


# file upload

post_param = reqparse.RequestParser()
post_param.add_argument('json_file',
                         type=datastructures.FileStorage,
                         location='files',
                         required=True,
                         help='JSON file')

# url parameter
url_param = reqparse.RequestParser()
url_param.add_argument('url', required=True, help='URL of JSON metadata document')

qual_url = reqparse.RequestParser()
qual_url.add_argument('url', required=True, help='URL of JSON metadata document')
qual_post = reqparse.RequestParser()
qual_post.add_argument('json_file',
                         type=datastructures.FileStorage,
                         location='files',
                         required=True,
                         help='JSON file')
for q in [qual_post, qual_url]:
    q.add_argument('format', required=False, choices=['json-ld', 'json', 'csv'], default='json',
                  help='Output format')

    q.add_argument('metric', required=False, action='append', help='Filter by a specific metric', choices=[m.lower() for m in dcat_analyser().keys()])