"""
Create a working directory for ctapipe-process containing standard
configuration files.
"""
from importlib.resources import files
from pathlib import Path
from ..core import Provenance, Tool, traits
from ..version import __version__ as VERSION
__all__ = ["QuickStartTool"]
CONFIGS_TO_WRITE = [
    "base_config.yaml",
    "calculate_pixel_stats.yaml",
    "stage1_config.yaml",
    "stage2_config.yaml",
    "ml_preprocessing_config.yaml",
    "train_energy_regressor.yaml",
    "train_particle_classifier.yaml",
    "train_disp_reconstructor.yaml",
    "optimize_cuts.yaml",
    "compute_irf.yaml",
]
README_TEXT = f"""
# ctapipe working directory
## ctapipe-process configs
This working directory contains some example configuration files that are useful
for processing data with `ctapipe-process`. These include:
- `base_config.yaml`: standard configuration options, to be included always
In addition several sub-configurations to be included after base_config.yaml
- `stage1_config.yaml`: generate DL1 data from lower data levels
- `stage2_config.yaml`: generate DL2 shower geometry from DL1 or lower levels
- `ml_preprocessing_config.yaml`: generate both DL1 parameter and DL2 shower geometry
      data, useful for training ML algorithms
You can modify these to change the output, and run ctapipe by including both the
base config plus one additional configuration using:
```
ctapipe-process --config base_config.yaml --config <CONFIG> --input <EVENTS FILE> --output <OUTPUT FILE>
```
Where <CONFIG> is one of the non-base configs above, <EVENTS FILE> is any
ctapipe-readable event file at a lower or equal data level to the one requested
to be produced.
Details about all configuration options can be found by running:
```
ctapipe-process --help-all
```
## ctapipe-train-energy-regressor / ctapipe-train-particle-classifier / ctapipe-train-disp-reconstructor configs
Included here are also base configurations for training machine learning (ML)
models for energy regression, gamma/hadron separation and disp origin reconstruction.
NOTE: As these files are used for unit tests, they are optimized for very fast training
and will not result in well performing models.
- `train_energy_regressor.yaml`: configuration of energy regression model
- `train_particle_classifier.yaml`: configuration of particle classification model
- `train_disp_reconstructor.yaml`: configuration of disp reconstruction models
## ctapipe-optimize-event-selection / ctapipe-compute-irf configs
There are also configuration files for the calculation of G/H and direction ('theta') cuts and
the calculation of IRF.
- `optimize_cuts.yaml`: configuration for cut calculation
- `compute_irf.yaml`: configuration for IRF calculation
These files contain the default values for all configuration options and are meant to make it easier
for you to create your own configuration files for these tools.
This file was generated using ctapipe version {VERSION}
"""
def copy_with_transforms(input_file: Path, output_file: Path, transforms: dict):
    """reads input_file and writes output_file, swapping text listed in the
    transformations dict
    Parameters
    ----------
    input_file: str
        template file to read
    output_file: str
        file to write
    transformations: Dict[str, str]
        dict of search and replacement strings
    """
    input_file = Path(input_file)
    output_file = Path(output_file)
    template = input_file.read_text()
    for find, replace in transforms.items():
        template = template.replace(find, replace)
    output_file.write_text(template)
def main():
    """run the tool"""
    tool = QuickStartTool()
    tool.run()
if __name__ == "__main__":
    main()