package app

import (
	"database/sql"

	"git.ctrlz.es/mgdelacroix/craban/model"
)

func (a *App) CreateGame(name string, userID int) (*model.Game, error) {
	return a.Store.Game().Create(name, userID)
}

func (a *App) AddMember(gameID, userID int, role string) (*model.GameMember, error) {
	return a.Store.Game().AddMember(gameID, userID, role)
}

func (a *App) ListGames() ([]*model.Game, error) {
	games, err := a.Store.Game().List()
	if err == sql.ErrNoRows {
		return []*model.Game{}, nil
	}
	return games, err
}

func (a *App) ListGamesForUser(userID int) ([]*model.Game, error) {
	games, err := a.Store.Game().ListForUser(userID)
	if err == sql.ErrNoRows {
		return []*model.Game{}, nil
	}
	return games, err
}
