from sqlalchemy import Column, ForeignKey, Integer, String, Float, types
from database import Base
import sqlalchemy.types as types


class NaiveStringList(types.TypeDecorator):
    impl = types.Unicode
    sep = "\n"

    def process_bind_param(self, value: list[str], dialect):
        allowed = list, tuple
        if not isinstance(value, allowed):
            raise ValueError(f"{value!r}'s type should be in types{allowed} ")
        return self.sep.join(value)

    def process_result_value(self, value, dialect):
        return value.split(self.sep)

    def copy(self, **kw):
        return NaiveStringList(self.impl.length)


class Movie(Base):
    __tablename__ = "movies"

    id = Column(Integer, primary_key=True, index=True)

    title = Column(String, index=True)

    vote_count = Column(Integer)
    vote_average = Column(Float)

    genres = Column(NaiveStringList)  # LLw
    # genres = Column(ARRAY(String, dimensions=1))  # String array dimention 1

    description = Column(String)
    release_date = Column(String)
