from typing import Optional
from typing import Tuple
from pathlib import Path
import shutil


def create_workspace(config: str, suffix: Optional[str] = None) -> Tuple[Path, Path]:
    """Create workspace to run steps and store results.

    Parameters
    ----------
    config : str or os.PathLike
        Original TRExFitter config file.
    suffix : str, optional
        Add a suffix to the workspace

    Returns
    -------
    pathlib.Path
        Created workspace path.
    pathlib.Path
        Copy of configuration file in the workspace.

    """
    config_path = Path(config)
    workspace = config_path.parent / f"{config_path.stem}.d"
    if suffix is not None:
        workspace = Path(f"{config_path.stem}.{suffix}.d")
    workspace.mkdir(exist_ok=True)
    if not (workspace / "fit.conf").exists():
        shutil.copyfile(config_path, workspace / "fit.conf")
    return workspace.absolute(), (workspace / "fit.conf").absolute()