import os.path
from datetime import datetime
from typing import Optional

from core.database.abc.db_model_abc import DbModelABC
from core.typing import SerialId


class File(DbModelABC):
    def __init__(
        self,
        id: SerialId,
        file_id: str,
        path: str,
        file_hash: str,
        deleted: bool = False,
        editor_id: Optional[SerialId] = None,
        created: Optional[datetime] = None,
        updated: Optional[datetime] = None,
    ):
        DbModelABC.__init__(self, id, deleted, editor_id, created, updated)

        self._file_id = file_id
        self._path = path
        self._file_hash = file_hash

    @property
    def file_id(self) -> str:
        return self._file_id

    @property
    def path(self) -> str:
        return self._path

    @property
    def file_hash(self) -> str:
        return self._file_hash

    @file_hash.setter
    def file_hash(self, value: str):
        self._file_hash = value

    @property
    def full_path(self) -> str:
        return os.path.join(self._path, self._file_id).replace("\\", "/")
