from shexer.consts import SHEXC, SHACL_TURTLE, ABSOLUTE_COUNT_PROP, EXAMPLE_CONFORMANCE_PROP
from shexer.io.shex.formater.shex_serializer import ShexSerializer
from shexer.io.shacl.formater.shacl_serializer import ShaclSerializer
from shexer.io.uml.uml_serializer import UMLSerializer
from shexer.io.rdfconfig.formater.rdfconfig_serializer import RdfConfigSerializer
from shexer.consts import RATIO_INSTANCES, UML_PLANT_SERVER, EXTRA_INFO_PROP, FREQ_PROP


def get_shape_serializer(output_format, shapes_list, instance_tracker, target_file=None, string_return=False,
                         namespaces_dict=None, instantiation_property=None, disable_comments=False,
                         wikidata_annotation=False, instances_report_mode=RATIO_INSTANCES, detect_minimal_iri=False,
                         shape_features_examples=None, examples_mode=None, inverse_paths=False,
                         rdfconfig_directory=None, endpoint_url=None, shape_map_raw=None, shape_map_file=None,
                         verbose=False, example_conformance_prop=EXAMPLE_CONFORMANCE_PROP, generate_annotations=False,
                         absolute_counts_prop=ABSOLUTE_COUNT_PROP, extra_info_prop=EXTRA_INFO_PROP,
                         frequency_prop=FREQ_PROP):


    if rdfconfig_directory is not None:
        return RdfConfigSerializer(target_directory=rdfconfig_directory,
                                   shapes_list=shapes_list,
                                   namespaces_dict=namespaces_dict,
                                   string_return=string_return,
                                   instantiation_property_str=instantiation_property,
                                   shape_example_features=shape_features_examples,
                                   endpoint_url=endpoint_url)
    if output_format == SHEXC:
        return ShexSerializer(target_file=target_file,
                              shapes_list=shapes_list,
                              namespaces_dict=namespaces_dict,
                              string_return=string_return,
                              instantiation_property_str=instantiation_property,
                              disable_comments=disable_comments,
                              wikidata_annotation=wikidata_annotation,
                              instances_report_mode=instances_report_mode,
                              detect_minimal_iri=detect_minimal_iri,
                              shape_example_features=shape_features_examples,
                              examples_mode=examples_mode,
                              inverse_paths=inverse_paths,
                              example_constraint_prop=example_conformance_prop,
                              comments_to_annotations=generate_annotations,
                              absolute_counts_prop=absolute_counts_prop)
    elif output_format == SHACL_TURTLE:
        return ShaclSerializer(target_file=target_file,
                               shapes_list=shapes_list,
                               namespaces_dict=namespaces_dict,
                               string_return=string_return,
                               instantiation_property_str=instantiation_property,
                               wikidata_annotation=wikidata_annotation,
                               shape_example_features=shape_features_examples,
                               detect_minimal_iri=detect_minimal_iri,
                               verbose=verbose,
                               shape_map=None if (shape_map_file is None and shape_map_raw is None)
                                               else instance_tracker.shape_map,
                               examples_mode=examples_mode,
                               comments_to_annotations=generate_annotations,
                               absolute_counts_prop=absolute_counts_prop,
                               extra_info_prop=extra_info_prop,
                               frequency_prop=frequency_prop,
                               example_constraint_prop=example_conformance_prop,
                               instances_report_mode=instances_report_mode)

    # example_constraint_prop = EXAMPLE_CONFORMANCE_PROP, comments_to_annotations = True,
    # absolute_counts_prop = ABSOLUTE_COUNT_PROP, extra_info_prop = EXTRA_INFO_PROP,
    # frequency_prop = FREQ_PROP
    else:
        raise ValueError("Currently unsupported format in 'output_format': " + output_format)


def get_uml_serializer(shapes_list, image_path, url_server=UML_PLANT_SERVER, namespaces_dict=None, ):
    return UMLSerializer(shapes_list=shapes_list,
                         url_server=url_server,
                         image_path=image_path,
                         namespaces_dict=namespaces_dict)
