from dataclasses import dataclass, field

from dataclasses_ujson.dataclasses_ujson import UJsonMixin  # type: ignore
from sqlalchemy import JSON, Column, String, Text

from server.infra.db.db_mapper import mapper_registry


@mapper_registry.mapped
@dataclass
class Beerds(UJsonMixin):
    __sa_dataclass_metadata_key__ = "sa"
    __tablename__ = "beerds"

    id: str = field(metadata={"sa": Column(String(), primary_key=True, nullable=False)})
    name: str = field(metadata={"sa": Column(Text(), nullable=False)})
    alias: str = field(metadata={"sa": Column(Text(), nullable=False)})
    descriptions: str = field(metadata={"sa": Column(Text(), nullable=False)})
    signs: dict | None = field(default=None, metadata={"sa": Column(JSON(), nullable=False)})
    kind: str | None = field(default=None, metadata={"sa": Column(Text(), nullable=True)})

    def __str__(self):
        return self.name
