from pathlib import Path
from typing import Optional
from datetime import datetime
import logging


def setup(criterion: str, query_type: str, outdir: Path, delta: Optional[float] = None):
    """ Normalizes flag strings, makes outdir, configures logging """
    assert delta is None or delta > 1.0, "Delta must be strcitly greater than 1"
    criterion = criterion.lower()
    query_type = query_type.lower()
    outpath = Path(outdir)
    outpath.mkdir(parents=True, exist_ok=True)

    now = datetime.now()

    logging.basicConfig(level="INFO", filename=outpath / f"{now}.log")

    assert criterion == "information" or criterion == "volume" or criterion == "random", (
        "There is no criterion called " + criterion
    )
    return criterion, query_type, outpath