# -*- coding: utf-8 -*-
#
# Copyright (C) 2021 CERN.
#
# Invenio-Vocabularies is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""Vocabulary affiliations configuration."""

from flask_babelex import lazy_gettext as _
from invenio_records_resources.services import SearchOptions
from invenio_records_resources.services.records.components import DataComponent
from invenio_records_resources.services.records.params import \
    SuggestQueryParser

from ...services.components import PIDComponent


class AffiliationsSearchOptions(SearchOptions):
    """Search options."""

    suggest_parser_cls = SuggestQueryParser.factory(
        fields=[
            'name^100',
            'acronym^20',
            'title.*^5',
            'title.*._2gram',
            'title.*._3gram',
        ],
    )

    sort_default = 'bestmatch'

    sort_default_no_query = 'name'

    sort_options = {
        "bestmatch": dict(
            title=_('Best match'),
            fields=['_score'],  # ES defaults to desc on `_score` field
        ),
        "name": dict(
            title=_('Name'),
            fields=['name_sort'],
        ),
        "newest": dict(
            title=_('Newest'),
            fields=['-created'],
        ),
        "oldest": dict(
            title=_('Oldest'),
            fields=['created'],
        ),
    }


service_components = [
    # Order of components are important!
    DataComponent,
    PIDComponent,
]
