CREATE TABLE TEST(
	ID text PRIMARY KEY
);

CREATE TABLE IF NOT EXISTS users (
  email text PRIMARY KEY,
  username text
);

CREATE TABLE IF NOT EXISTS sessions (
  session_id text PRIMARY KEY,
  access_token text NOT NULL,
  user_email text NOT NULL,
  FOREIGN KEY(user_email) REFERENCES users(email)
);

CREATE TABLE IF NOT EXISTS game_settings (
  lobby_id text PRIMARY KEY,
  max_players integer,
  game_mode text,
  selected_playlist_id text
);

CREATE TABLE IF NOT EXISTS lobbys (
  lobby_id text PRIMARY KEY,
  host_email text,
  game_settings_id text,
  FOREIGN KEY(game_settings_id) REFERENCES game_settings(lobby_id),
  FOREIGN KEY(host_email) REFERENCES users(email)
);

CREATE TABLE IF NOT EXISTS users_in_lobbys (
  user_email text PRIMARY KEY,
  lobby_id text,
  FOREIGN KEY(user_email) REFERENCES users(email),
  FOREIGN KEY(lobby_id) REFERENCES lobbys(lobby_id)
);

CREATE TABLE IF NOT EXISTS auth_states (
  state_id text PRIMARY KEY,
  code_verifier text NOT NULL
);
