major-domo-v2/models/draft_data.py
Cal Corum 9cd577cba1 fix: batch quick-wins — 4 issues resolved (closes #37, #27, #25, #38)
- #37: Fix stale comment in transaction_freeze.py referencing wrong moveid format
- #27: Change config.testing default from True to False (was masking prod behavior)
- #25: Replace deprecated asyncio.get_event_loop() with get_running_loop()
- #38: Replace naive datetime.now() with timezone-aware datetime.now(UTC) across
  7 source files and 4 test files to prevent subtle timezone bugs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 11:48:16 -06:00

68 lines
2.1 KiB
Python

"""
Draft configuration and state model
Represents the current draft settings and timer state.
"""
from typing import Optional
from datetime import UTC, datetime
from pydantic import Field, field_validator
from models.base import SBABaseModel
class DraftData(SBABaseModel):
"""Draft configuration and state model."""
currentpick: int = Field(0, description="Current pick number in progress")
timer: bool = Field(False, description="Whether draft timer is active")
paused: bool = Field(
False, description="Whether draft is paused (blocks all picks)"
)
pick_deadline: Optional[datetime] = Field(
None, description="Deadline for current pick"
)
result_channel: Optional[int] = Field(
None, description="Discord channel ID for draft results"
)
ping_channel: Optional[int] = Field(
None, description="Discord channel ID for draft pings"
)
pick_minutes: int = Field(1, description="Minutes allowed per pick")
@field_validator("result_channel", "ping_channel", mode="before")
@classmethod
def cast_channel_ids_to_int(cls, v):
"""Ensure channel IDs are integers (database stores as string)."""
if v is None:
return None
if isinstance(v, str):
return int(v)
return v
@property
def is_draft_active(self) -> bool:
"""Check if the draft is currently active (timer running and not paused)."""
return self.timer and not self.paused
@property
def is_pick_expired(self) -> bool:
"""Check if the current pick deadline has passed."""
if not self.pick_deadline:
return False
return datetime.now(UTC) > self.pick_deadline
@property
def can_make_picks(self) -> bool:
"""Check if picks are allowed (not paused)."""
return not self.paused
def __str__(self):
if self.paused:
status = "PAUSED"
elif self.timer:
status = "Active"
else:
status = "Inactive"
return f"Draft {status}: Pick {self.currentpick} ({self.pick_minutes}min timer)"