package races import ( "context" "github.com/x0gp/server/internal/lobby" ) // LiveStore is a thin facade over PgStore that exposes only the live // race persistence methods. It implements the lobby.Persistence // contract so the lobby can write through it. // // Methods on this type are kept separate from the rest of PgStore // purely for clarity: the lobby-facing surface is small and // well-defined. All actual work is delegated to PgStore. type LiveStore struct { pg *PgStore } // NewLiveStore wraps an existing PgStore. func NewLiveStore(pg *PgStore) *LiveStore { return &LiveStore{pg: pg} } func (s *LiveStore) UpsertRace(ctx context.Context, r lobby.RaceMeta) error { return s.pg.UpsertLive(ctx, r) } func (s *LiveStore) DeleteRace(ctx context.Context, raceID string) error { return s.pg.DeleteLive(ctx, raceID) } func (s *LiveStore) AddDriver(ctx context.Context, raceID, driverID string, slot int) error { return s.pg.AddLiveDriver(ctx, raceID, driverID, slot) } func (s *LiveStore) RemoveDriver(ctx context.Context, raceID, driverID string) error { return s.pg.RemoveLiveDriver(ctx, raceID, driverID) } func (s *LiveStore) SetRaceStatus(ctx context.Context, raceID string, status lobby.RaceStatus, startedMs int64) error { return s.pg.SetLiveStatus(ctx, raceID, status, startedMs) } func (s *LiveStore) UpsertDriver(ctx context.Context, d lobby.DriverMeta) error { return s.pg.UpsertLobbyDriver(ctx, d) } func (s *LiveStore) DeleteDriver(ctx context.Context, driverID string) error { return s.pg.DeleteLobbyDriver(ctx, driverID) } // ListAllRaces returns every live row in the unified races table. // Used by RestoreFromDB to rehydrate the in-memory lobby. func (s *LiveStore) ListAllRaces(ctx context.Context) ([]lobby.RaceMeta, error) { return s.pg.ListAllRaces(ctx) } // ListAllDrivers returns all lobby drivers from the lobby_drivers table. func (s *LiveStore) ListAllDrivers(ctx context.Context) ([]lobby.DriverMeta, error) { return s.pg.ListLobbyDrivers(ctx) } // ListLivePaged exposes a keyset page of live races. func (s *LiveStore) ListLivePaged(ctx context.Context, statuses []string, trackID string, cur Cursor, limit int) ([]lobby.RaceMeta, error) { return s.pg.ListLivePaged(ctx, statuses, trackID, cur, limit) } // ListUpcoming returns the next N open live races. func (s *LiveStore) ListUpcoming(ctx context.Context, limit int) ([]lobby.RaceMeta, error) { return s.pg.ListLiveUpcoming(ctx, limit) } // Exec exposes raw SQL for the seeder. func (s *LiveStore) Exec(ctx context.Context, sql string) (int64, error) { return s.pg.Exec(ctx, sql) }