#!/usr/bin/env python3

from .RoutingProfile import RoutingProfile
from .OSMDataset import OSMDataset
from .POIDataset import POIDataset
from .Scenario import Scenario

from functools import partial
from pathlib import Path

class Environment():
    """
    Environment is a convenience class to set default options for the `tebetebe` base classes.

    Many of the `tebetebe` operations require writing a file to disk in order to be passed
    to the OSRM executables, and it's useful to set a uniform `tmp_dir` for a particular set of
    commands so that all of these files generated by those commands are contained in the same place.

    In addition to `tmp_dir`, any **kwarg passed to Environment will be passed to all of the
    classes available under the Environment. Useful examples of these kwargs include `verbose`
    and `overwrite`

    Any **kwargs set in Environment classes will be overridden if the argument is specified during
    subclass initialization.

    Parameters
    ----------
    **kwargs
        Arbitrary keyword arguments to be passed to each class available under the Environment
    """
    def __init__(self, **kwargs):

        ## Set all env options to this class (set tmp_dir as a Path)
        for k_name, kwarg in kwargs.items():
            setattr(self, k_name, Path(kwarg) if k_name == "tmp_dir" else kwarg)

        self.RoutingProfile = partial(RoutingProfile, **kwargs)
        self.OSMDataset = partial(OSMDataset, **kwargs)
        self.POIDataset = partial(POIDataset, **kwargs)
        self.Scenario = partial(Scenario, **kwargs)

        self.OSMDataset.from_overpass = partial(OSMDataset.from_overpass, **kwargs)
        self.POIDataset.from_overpass = partial(POIDataset.from_overpass, **kwargs)
