import logging
import os
from inspect import stack
from pathlib import Path

import click
from pandas import DataFrame

from com.enovation.toolbox.predictability.bean import PredictabilityBean
from com.enovation.toolbox.predictability.dp_date_predictability.dp_computer import DatePredictabilityComputer


_logger: logging.Logger = logging.getLogger(__name__)


@click.command('dp_demo')
@click.argument('file', type=click.Path(exists=False))
@click.pass_context
def dp_demo_date_predictability(ctx_context, file):
    """
    Demonstration of how to use commands related to Date Predictability.

    FILE is the path to persist the outputs generated by the Date Predictability commands.
    """
    _logger.debug(f"Function '{stack()[0].filename} - {stack()[0].function}' is called")

    click.echo(f"**************************\nCopy past in your terminal the command generated below. The generated "
               f"command will do the following:"
               f"\n\t- Load a demo csv file"
               f"\n\t- Rename columns"
               f"\n\t- Compute date predictability")
    click.echo(
        f"python3 \"{Path(__file__).resolve().parents[5].joinpath('enov.py')}\" --verbose "
               
        f"load-csv -c 'Project and phase' -c 'Projection date' -c 'Projected ETA' "
        f"\"{Path(__file__).resolve().parents[0].joinpath('dp_demo.csv')}\" df_raw "
       
        f"rename-columns -o df_renamed df_raw "
        f"'{{\"Project and phase\":\"key\",\"Projection date\":\"date\",\"Projected ETA\":\"measure\"}}' "
        
        f"dp_compute -o df_predictability df_renamed "
        
        f"dp_persist df_predictability \"{file}\" "

        f"dp_graph df_predictability")

    """
    python3 ./enov.py --verbose \
      load-csv -c id -c timestamp -c ps_kick_off_date ~/Documents/07.PRO/04.ENOVATION/2021-06-29.MX.TestFiles/00.pipeline_history.csv df_raw \
      rename-columns -o df_renamed df_raw '{"id":"key","timestamp":"date","ps_kick_off_date":"measure"}' \
      cleanse-null-values -o df_cleansed df_renamed measure \
      compute_date_predictability -o df_predictability df_cleansed \
      write_predictability df_predictability ~/Documents/07.PRO/04.ENOVATION/2021-06-29.MX.TestFiles/jsg.bean.xlsx
      """

    _logger.debug(f"Function '{stack()[0].filename} - {stack()[0].function}' is returning")
