from sqlalchemy import (
    Column,
    BigInteger,
    Integer,
    String,
    DateTime,
    Boolean,
    func,
)

from app import db
from core.domains.plant.entity.plant_entity import PlantCategoryEntity


class PlantCategoryModel(db.Model):
    __tablename__ = "plant_categories"

    id = Column(
        BigInteger().with_variant(Integer, "sqlite"),
        primary_key=True,
        nullable=False,
        autoincrement=True,
    )
    name = Column(String(10), nullable=False)
    is_available = Column(Boolean, nullable=False, default=True)
    created_at = Column(DateTime(), server_default=func.now(), nullable=False)
    updated_at = Column(
        DateTime(), server_default=func.now(), onupdate=func.now(), nullable=False
    )

    def to_entity(self) -> PlantCategoryEntity:
        return PlantCategoryEntity(id=self.id, name=self.name,)
