from minio import Minio
import os
from typing import Optional
from glob import glob
import pathlib
from sqlmodel import Field, Session, SQLModel, create_engine

def get_images(folder:str="../cls_labeling/public/images"):
    return glob(str(pathlib.Path(folder,"**","*.jpg")), recursive=True)


class Image(SQLModel, table=True):
    key: Optional[int] = Field(default=None, primary_key=True)
    image_name: str
    label: str
    image_url: str


if __name__ == "__main__":
    engine = create_engine("sqlite:///image.db")
    client = Minio(
        "localhost:9001",
        secure=False,
        access_key="<KEY>",
        secret_key="<KEY>"
    )

    bucket_found = client.bucket_exists("image")
    if not bucket_found:
        client.make_bucket("image")
    else:
        for obj in client.list_objects("image"):
            client.remove_object("image", obj.object_name)
        client.remove_bucket("image")
        client.make_bucket("image")
        os.remove("./image.db")

    