Coverage for models/matches.py: 91.94%
60 statements
« prev ^ index » next coverage.py v7.10.6, created at 2026-11-30 20:17 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2026-11-30 20:17 +0000
1"""
2Match-related Pydantic models.
3"""
5from datetime import datetime
7from pydantic import BaseModel
10class EnhancedMatch(BaseModel):
11 """Model for creating or updating a match with full context."""
13 match_date: str
14 home_team_id: int
15 away_team_id: int
16 home_score: int
17 away_score: int
18 season_id: int
19 age_group_id: int
20 match_type_id: int
21 division_id: int | None = None
22 status: str | None = "scheduled" # scheduled, played, postponed, cancelled (maps to match_status in DB)
23 created_by: str | None = None # User ID who created the match (for audit trail)
24 updated_by: str | None = None # User ID who last updated the match
25 source: str = "manual" # Source: manual, match-scraper, import
26 external_match_id: str | None = None # External match identifier (e.g., from match-scraper)
27 scheduled_kickoff: datetime | None = None # Scheduled kickoff datetime in UTC
28 home_penalty_score: int | None = None # Penalty shootout score (only when regulation ends in draw)
29 away_penalty_score: int | None = None
30 # Age group a side fielded when it played up/down (SB-1444). Omitted =
31 # same as age_group_id, which is every scraped match.
32 home_age_group_id: int | None = None
33 away_age_group_id: int | None = None
36class MatchPatch(BaseModel):
37 """Model for partial match updates."""
39 home_score: int | None = None
40 away_score: int | None = None
41 match_status: str | None = None
42 match_date: str | None = None
43 home_team_id: int | None = None
44 away_team_id: int | None = None
45 season_id: int | None = None
46 age_group_id: int | None = None
47 match_type_id: int | None = None
48 division_id: int | None = None
49 status: str | None = None
50 external_match_id: str | None = None # External match identifier
51 scheduled_kickoff: datetime | None = None # Scheduled kickoff datetime in UTC
52 # Minutes per half. Normally set once by start_first_half, but that action
53 # is idempotent, so a wrong value chosen at kickoff was previously
54 # uncorrectable (SB-678). The clock is derived from timestamps + this
55 # value, so patching it immediately corrects the displayed minute, the
56 # halftime prompt and extra time. Recorded events keep their own minutes.
57 half_duration: int | None = None
58 home_penalty_score: int | None = None # Penalty shootout score (only when regulation ends in draw)
59 away_penalty_score: int | None = None
60 home_age_group_id: int | None = None # SB-1444; explicit null clears
61 away_age_group_id: int | None = None
63 class Config:
64 # Validation for scores
65 @staticmethod
66 def validate_score(v):
67 if v is not None and v < 0:
68 raise ValueError("Score must be non-negative")
69 return v
72class MatchSubmissionData(BaseModel):
73 """
74 Match data for async submission to Celery queue.
75 This model accepts flexible data from match-scraper.
76 """
78 home_team: str # Team name (will be looked up)
79 away_team: str # Team name (will be looked up)
80 match_date: str # ISO format date
81 season: str # Season name (e.g., "2024-25")
82 age_group: str | None = None
83 division: str | None = None
84 home_score: int | None = None
85 away_score: int | None = None
86 match_status: str = "scheduled" # scheduled, live, played, postponed, cancelled
87 match_type: str | None = None
88 location: str | None = None
89 external_match_id: str | None = None # External identifier for deduplication