from pathlib import Path
from typing import Any, List

from hartware_lib.utils import filesystem


class DirectoryAdapter:
    def __init__(self, dir_path: Path):
        self.dir_path = dir_path

    def create(self) -> None:
        filesystem.create_dir(self.dir_path)

    def delete(self) -> None:
        filesystem.delete_dir(self.dir_path)

    def delete_file(self, filename: str) -> None:
        filesystem.delete_file(self.dir_path / filename)

    def search(self, filename: str = "*") -> List[Path]:
        return filesystem.search_files(self.dir_path / "**" / filename)

    def exists(self) -> bool:
        return filesystem.exists(self.dir_path)

    def file_exists(self, filename: str) -> bool:
        return filesystem.exists(self.dir_path / filename)

    def read_file(self, filename: str) -> str:
        return filesystem.read_file(self.dir_path / filename)

    def write_file(self, filename: str, data: str = "") -> None:
        filesystem.write_file(self.dir_path / filename, data)

    def read_json(self, filename: str, **kwargs: Any) -> dict:
        return filesystem.read_json(self.dir_path / filename, **kwargs)

    def write_json(self, filename: str, data: dict, **kwargs: Any) -> None:
        filesystem.write_json(self.dir_path / filename, data, **kwargs)
