from sqlalchemy import Column, Integer, String, Float, Boolean, Text, ForeignKey
from database import Base


class Client(Base):
    __tablename__ = "clients"
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String, unique=True, index=True)
    color = Column(String)


class Deal(Base):
    __tablename__ = "deals"
    id = Column(Integer, primary_key=True, index=True)
    client_id = Column(Integer, ForeignKey("clients.id"))
    name = Column(String)
    shade_index = Column(Integer, default=0)
    status = Column(String, default="active")


class BoardColumn(Base):
    __tablename__ = "columns"
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String)
    sort_order = Column(Integer, default=0)


class Task(Base):
    __tablename__ = "tasks"
    id = Column(Integer, primary_key=True, index=True)
    title = Column(String)
    client_id = Column(Integer, ForeignKey("clients.id"))
    deal_id = Column(Integer, ForeignKey("deals.id"))
    column_id = Column(Integer, ForeignKey("columns.id"))
    due_date = Column(String, nullable=True)
    is_quick = Column(Boolean, default=False)
    assignee = Column(String, nullable=True)
    waiting_on = Column(String, nullable=True)
    notes = Column(Text, nullable=True)
    completed_at = Column(String, nullable=True)
    master_priority = Column(Float, default=0.0)
    column_priority = Column(Float, default=0.0)
    created_at = Column(String)


class Template(Base):
    __tablename__ = "templates"
    id = Column(Integer, primary_key=True, index=True)
    name = Column(String)
    items = Column(Text)


class StateSnapshot(Base):
    __tablename__ = "state_snapshots"
    id = Column(Integer, primary_key=True, index=True)
    key = Column(String, unique=True, index=True, default="default")
    data = Column(Text)
    updated_at = Column(String)
