from ... import db
from .base_model import Base


class Object(Base):
    __tablename__ = "kds_object"

    # Columns with data types
    obj_object_id: int = db.Column(db.Integer, primary_key=True, autoincrement=True)
    obj_parent_id: int = db.Column(
        db.Integer, db.ForeignKey("kds_object.obj_object_id")
    )
    obj_kitchen_id: int = db.Column(db.Integer)
    obj_reference: str = db.Column(db.Text)
    obj_type: str = db.Column(db.Text)
    obj_json: str = db.Column(db.Text)
    obj_status: str = db.Column(db.Text)
    obj_create_dt = db.Column(db.DateTime, default=db.func.current_timestamp())
    obj_update_dt = db.Column(
        db.DateTime,
        default=db.func.current_timestamp(),
        onupdate=db.func.current_timestamp(),
    )
    # relations
    children = db.relationship("Object")

    def __repr__(self):
        return "<Object %r>" % (self.obj_reference)
