#!/usr/bin/python3

r"""
Produces a markdown file for a given array element, site, and model version.

The report includes detailed information on each parameter,
such as the parameter name, value, unit, description, and short description.
Currently only implemented for telescopes.
"""

import logging

from simtools.configuration import configurator
from simtools.io_operations import io_handler
from simtools.reporting.docs_read_parameters import ReadParameters
from simtools.utils import general as gen


def _parse(label):
    """Parse command line configuration."""
    config = configurator.Configurator(
        label=label,
        description=("Produce a markdown report for model parameters."),
    )

    config.parser.add_argument(
        "--parameter",
        action="store_true",
        help="Compare all parameters across model versions for one telescope.",
    )

    return config.initialize(
        db_config=True, simulation_model=["site", "telescope", "model_version", "parameter_version"]
    )


def main():  # noqa: D103
    label_name = "reports"
    args, db_config = _parse(label_name)
    io_handler_instance = io_handler.IOHandler()
    output_path = io_handler_instance.get_output_directory(
        label=label_name, sub_dir=f"productions/{args['model_version']}"
    )

    logger = logging.getLogger()
    logger.setLevel(gen.get_log_level_from_user(args["log_level"]))

    ReadParameters(
        db_config,
        args,
        output_path,
    ).produce_array_element_report()

    logger.info(
        f"Markdown report generated for {args['site']}"
        f" Telescope {args['telescope']} (v{args['model_version']}):"
        f" {output_path}"
    )


if __name__ == "__main__":
    main()
