from pydantic import BaseModel
from typing import List, Optional
from datetime import datetime

class TrackBase(BaseModel):
    id: str
    name: str
    artist: str
    album: str
    duration_ms: int
    popularity: Optional[int] = None
    lyrics_summary: Optional[str] = None
    genre_tags: Optional[str] = None

    # Audio Features
    danceability: Optional[float] = None
    energy: Optional[float] = None
    valence: Optional[float] = None
    tempo: Optional[float] = None
    key: Optional[int] = None
    mode: Optional[int] = None
    acousticness: Optional[float] = None
    instrumentalness: Optional[float] = None
    liveness: Optional[float] = None
    speechiness: Optional[float] = None
    loudness: Optional[float] = None

class Track(TrackBase):
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True

class PlayHistoryBase(BaseModel):
    track_id: str
    played_at: datetime
    context_uri: Optional[str] = None

class PlayHistory(PlayHistoryBase):
    id: int
    track: Track

    class Config:
        from_attributes = True
