from sqlalchemy import Column, Integer, String, ForeignKey, Text
from sqlalchemy.orm import declarative_base, relationship

Base = declarative_base()

class Admin(Base):
    __tablename__ = 'admins'
    id = Column(Integer, primary_key=True)
    tg_id = Column(Integer, unique=True, nullable=False)

class Channel(Base):
    __tablename__ = 'channels'
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
    link = Column(String, nullable=False)
    buttons = relationship('Button', back_populates='channel')

class Group(Base):
    __tablename__ = 'groups'
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
    link = Column(String, nullable=False)
    buttons = relationship('Button', back_populates='group')

class Button(Base):
    __tablename__ = 'buttons'
    id = Column(Integer, primary_key=True)
    name = Column(String, nullable=False)
    url = Column(String, nullable=False)
    channel_id = Column(Integer, ForeignKey('channels.id'), nullable=True)
    group_id = Column(Integer, ForeignKey('groups.id'), nullable=True)
    channel = relationship('Channel', back_populates='buttons')
    group = relationship('Group', back_populates='buttons')
