from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Table
from sqlalchemy.orm import relationship
from datetime import datetime
from ...shared.config.database import Base

# Association table for many-to-many relationship between users and tags
guest_tag_association = Table(
    'guest_tag_associations',
    Base.metadata,
    Column('user_id', Integer, ForeignKey('users.id'), primary_key=True),
    Column('tag_id', Integer, ForeignKey('guest_tags.id'), primary_key=True),
    Column('created_at', DateTime, default=datetime.utcnow, nullable=False)
)

class GuestTag(Base):
    __tablename__ = 'guest_tags'
    id = Column(Integer, primary_key=True, index=True, autoincrement=True)
    name = Column(String(50), unique=True, nullable=False, index=True)
    color = Column(String(7), nullable=True, default='#3B82F6')  # Hex color code
    description = Column(String(255), nullable=True)
    created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
    
    users = relationship('User', secondary=guest_tag_association, back_populates='guest_tags')

