DROP TABLE IF EXISTS goals;
DROP TABLE IF EXISTS reward_queue;
DROP TABLE IF EXISTS votes;
DROP TABLE IF EXISTS cool_downs;

CREATE TABLE IF NOT EXISTS points (
  id TEXT PRIMARY KEY,
  name TEXT,
  points INTEGER,  
  user_authed BOOLEAN NOT NULL,
  email TEXT,
  code INTEGER
);

CREATE TABLE goals (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  progress INTEGER NOT NULL,
  target INTEGER NOT NULL,
  complete BOOLEAN NOT NULL,
  info TEXT,
  milestones INTEGER
);

CREATE TABLE votes (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  count INTEGER NOT NULL,
  voters TEXT,
  info TEXT
);

CREATE TABLE reward_queue (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  reward TEXT NOT NULL,
  user_id TEXT NOT NULL,
  fulfilled BOOLEAN NOT NULL,
  refunded BOOLEAN NOT NULL,
  FOREIGN KEY (user_id) REFERENCES points (id)
);

CREATE TABLE cool_downs (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  created REAL NOT NULL,
  reward TEXT NOT NULL
);
