import mimetypes

from snek.system.model import BaseModel, ModelField


class DriveItemModel(BaseModel):
    drive_uid = ModelField(name="drive_uid", required=True, kind=str)
    name = ModelField(name="name", required=True, kind=str)
    path = ModelField(name="path", required=True, kind=str)
    file_type = ModelField(name="file_type", required=True, kind=str)
    file_size = ModelField(name="file_size", required=True, kind=int)
    is_available = ModelField(
        name="is_available", required=True, kind=bool, initial_value=True
    )

    @property
    def extension(self):
        return self["name"].split(".")[-1]

    @property
    def mime_type(self):
        mimetype, _ = mimetypes.guess_type(self["name"])
        return mimetype
