import bpy

from pathlib import Path
from dataclasses import dataclass


class FangeProject:
    """
    This object is a model to give all Unity project path.
    """
    def __init__(self):
        self._pref = bpy.context.preferences.addons[__name__.split(".")[0]].preferences

        self._project_path = Path(self._pref.project_path)
        self._subdir_path = Path(self._pref.subdir_graph)

        self._building_path = Path(self._pref.subdir_buildings)
        self._props_path = Path(self._pref.subdir_props)
        self._characters_path = Path(self._pref.subdir_characters)

    @property
    def buildings(self):
        """Get the buildings project path, on absolute"""
        return self._project_path.joinpath(self._subdir_path, self._building_path)

    @property
    def props(self):
        return self._project_path.joinpath(self._subdir_path, self._props_path)

    @property
    def characters(self):
        return self._project_path.joinpath(self._subdir_path, self._characters_path)


@dataclass
class Collection:
    name: str
    color: str


class Outline:
    """
    Model about the Outline config.
    """
    def __init__(self):
        self._collections = {
            'Placeholder': Collection(name='Placeholder', color='COLOR_01'),
            'Icon': Collection(name='Icon', color='COLOR_04'),
            'Game Object': Collection(name='Game Object', color='COLOR_05')
        }

        self._socket = Collection(name='Socket', color='NONE')

    @property
    def collections(self) -> [str]:
        """Returns all collections in a dict"""
        return self._collections

    @property
    def get_placeholder_collection(self):
        return bpy.data.collections.get(self.collections['Placeholder'].name)

    @property
    def get_icon_collection(self):
        return bpy.data.collections.get(self.collections['Icon'].name)

    @property
    def get_game_object_collection(self):
        return bpy.data.collections.get(self.collections['Game Object'].name)

    @property
    def socket(self) -> Collection:
        return self._socket
