Coverage for models/post_match.py: 100.00%
32 statements
« prev ^ index » next coverage.py v7.10.6, created at 2026-11-30 15:03 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2026-11-30 15:03 +0000
1"""
2Post-Match Stats Pydantic models.
4Models for recording goals, substitutions, and player stats
5after a match has been completed.
6"""
8from pydantic import BaseModel, Field
11class PostMatchGoal(BaseModel):
12 """Model for recording a post-match goal event."""
14 team_id: int = Field(..., description="ID of the team that scored")
15 player_id: int | None = Field(None, description="ID of the goal scorer from roster (preferred)")
16 player_name: str | None = Field(None, max_length=200, description="Name of goal scorer (when no roster)")
17 assist_player_id: int | None = Field(None, description="ID of the assisting player from roster")
18 match_minute: int = Field(..., ge=1, le=130, description="Minute the goal was scored")
19 extra_time: int | None = Field(None, ge=1, description="Stoppage time minutes (e.g., 3 for 45+3)")
20 message: str | None = Field(None, max_length=500, description="Optional goal description")
23class PostMatchSubstitution(BaseModel):
24 """Model for recording a post-match substitution event."""
26 team_id: int = Field(..., description="ID of the team making the substitution")
27 player_in_id: int = Field(..., description="ID of the player coming on")
28 player_out_id: int = Field(..., description="ID of the player coming off")
29 match_minute: int = Field(..., ge=1, le=130, description="Minute the substitution occurred")
30 extra_time: int | None = Field(None, ge=1, description="Stoppage time minutes")
33class PostMatchCard(BaseModel):
34 """Model for recording a post-match card event (yellow or red)."""
36 team_id: int = Field(..., description="ID of the team the player belongs to")
37 player_id: int | None = Field(None, description="ID of the carded player from roster (preferred)")
38 player_name: str | None = Field(None, max_length=200, description="Name of player (when no roster)")
39 card_type: str = Field(..., pattern="^(yellow_card|red_card)$", description="Type of card: yellow_card or red_card")
40 match_minute: int = Field(..., ge=1, le=130, description="Minute the card was given")
41 extra_time: int | None = Field(None, ge=1, description="Stoppage time minutes")
42 message: str | None = Field(None, max_length=500, description="Optional description (e.g., reason for card)")
45class PlayerStatEntry(BaseModel):
46 """Model for a single player's match stats update."""
48 player_id: int = Field(..., description="Player ID from roster")
49 started: bool = Field(..., description="Whether the player started the match")
50 played: bool = Field(..., description="Whether the player participated in the match")
51 minutes_played: int = Field(..., ge=0, le=130, description="Total minutes played")
52 yellow_cards: int = Field(0, ge=0, le=2, description="Yellow cards received (0-2)")
53 red_cards: int = Field(0, ge=0, le=1, description="Red cards received (0-1)")
56class BatchPlayerStatsUpdate(BaseModel):
57 """Model for batch-updating player stats for a team in a match."""
59 players: list[PlayerStatEntry] = Field(..., min_length=1, description="List of player stat entries")