| """ |
| Color database model for Google Calendar API v3 color definitions |
| """ |
|
|
| from sqlalchemy import Column, Integer, String, DateTime, Enum, ForeignKey |
| from sqlalchemy.orm import relationship |
| from datetime import datetime, timezone |
| from .base import Base |
| import enum |
|
|
|
|
| class ColorType(enum.Enum): |
| """Color type enumeration""" |
| CALENDAR = "calendar" |
| EVENT = "event" |
|
|
|
|
| class Color(Base): |
| """Color database model for calendar and event color definitions""" |
| |
| __tablename__ = "colors" |
| |
| id = Column(Integer, primary_key=True, autoincrement=True) |
| color_id = Column(String(10), nullable=False, index=True) |
| color_type = Column(Enum(ColorType), nullable=False, index=True) |
| background = Column(String(7), nullable=False) |
| foreground = Column(String(7), nullable=False) |
| created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc)) |
| updated_at = Column(DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc)) |
| |
| |
| events = relationship("Event", back_populates="color") |
| |
| |
| __table_args__ = ( |
| {'mysql_charset': 'utf8mb4'} |
| if hasattr(__builtins__, 'mysql') |
| else {} |
| ) |
| |
| def __repr__(self): |
| return f"<Color(id='{self.color_id}', type='{self.color_type.value}', bg='{self.background}', fg='{self.foreground}')>" |
| |
| def to_dict(self): |
| """Convert to dictionary format for API responses""" |
| return { |
| "background": self.background, |
| "foreground": self.foreground |
| } |