#!/usr/bin/env python
"""Create Elasticsearch indices for the zm-rag system.

Usage::

    python -m scripts.init_es_index
"""

from __future__ import annotations

import asyncio
import sys
from pathlib import Path

# Ensure the project root is on sys.path so ``app`` is importable.
_project_root = Path(__file__).resolve().parent.parent
if str(_project_root) not in sys.path:
    sys.path.insert(0, str(_project_root))

from app.infrastructure.es_client import ESClient  # noqa: E402
from app.utils.logger import configure_logging, get_logger  # noqa: E402

logger = get_logger(__name__)


async def main() -> None:
    configure_logging(debug=True)
    logger.info("init_es_index_start")

    client = ESClient.from_settings()
    try:
        await client.create_indices()
        logger.info("init_es_index_done")
    finally:
        await client.close()


if __name__ == "__main__":
    asyncio.run(main())
