import pprint

from meilisearch import Client as Meilisearch

MASTER_KEY = 'zrYPsSAG1hgq2zB1dkF0sB9xLoIwTLAz6uw38pWRf5abdpTjY2eeMTIsfPbDbqQR'
API_KEY = '1aa4c720611269e9425e8467df7e802f3a20ad6c5f31fe875ac886fc4efa2c83'

client = Meilisearch(
    # 'https://meili.vps.eduseg.com.br',
    # '1aa4c720611269e9425e8467df7e802f3a20ad6c5f31fe875ac886fc4efa2c83',
    'http://localhost:7700'
)

pp = pprint.PrettyPrinter(indent=4)

courses = client.index('test-courses')

courses.update_settings(
    {
        'sortableAttributes': ['create_date'],
        'filterableAttributes': ['tenant__org_id'],
    }
)


# with open('cli/search-results.json') as fp:
#     docs = json.load(fp)
#     courses.add_documents(docs)

# pp.pprint(courses.search(''))

# client.create_index('betaeducacao-prod-orders', {'primaryKey': 'id'})
# client.create_index('betaeducacao-prod-enrollments', {'primaryKey': 'id'})
# client.create_index('betaeducacao-prod-users_d2o3r5gmm4it7j', {'primaryKey': 'id'})

# An index is where the documents are stored.
# index = client.index('users')

# pp.pprint(index.search(query='*'))

# documents = [
#     {'id': 1, 'title': 'Carol', 'genres': ['Romance', 'Drama']},
#     {'id': 2, 'title': 'Wonder Woman', 'genres': ['Action', 'Adventure']},
#     {'id': 3, 'title': 'Life of Pi', 'genres': ['Adventure', 'Drama']},
#     {
#         'id': 4,
#         'title': 'Mad Max: Fury Road',
#         'genres': ['Adventure', 'Science Fiction'],
#     },
#     {'id': 5, 'title': 'Moana', 'genres': ['Fantasy', 'Action']},
#     {'id': 6, 'title': 'Philadelphia', 'genres': ['Drama']},
# ]

# # # If the index 'movies' does not exist, Meilisearch creates it when you first add the documents.
# index.add_documents(documents
#
# )


# pp.pprint(client.get_keys({'limit': 3}).model_dump_json())
#
# uid='fdbdda56-00dd-4f53-934f-6629f3b08ee3' name=None description='Add, get documents and search' actions=['documents.add', 'documents.get', 'search'] indexes=['users', 'courses', 'enrollments', 'orders'] expires_at=None key='1aa4c720611269e9425e8467df7e802f3a20ad6c5f31fe875ac886fc4efa2c83' created_at=datetime.datetime(2025, 4, 1, 0, 46, 27, 751365) updated_at=datetime.datetime(2025, 4, 1, 0, 46, 27, 751365)
