\set title cards
DROP TABLE IF EXISTS cards;
DROP SEQUENCE IF EXISTS cards_record_num_sequence;

CREATE SEQUENCE cards_record_num_sequence;
CREATE SEQUENCE cards_card_id_sequence;

CREATE TABLE cards (
  record_num        INTEGER PRIMARY KEY DEFAULT nextval('cards_record_num_sequence'),
  card_id           INTEGER      NOT NULL DEFAULT nextval('cards_card_id_sequence'),
  data_id           VARCHAR(100) NOT NULL,
  lore_name         VARCHAR(20),
  lore_description  VARCHAR(255),
  placement_flags   SMALLINT, -- 2^0 => empty cell, 2^1 => near track, 2^2 => near building, 2^3 => on track
  hstore            HSTORE, -- Store any kind of card specific data?? resources, minions, enemies generated, etc...
  created_timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);



DROP TABLE IF EXISTS units;
DROP SEQUENCE IF EXISTS units_record_num_sequence;
DROP SEQUENCE IF EXISTS units_unit_id_sequence;

CREATE SEQUENCE units_record_num_sequence;
CREATE SEQUENCE units_unit_id_sequence;

CREATE TABLE units (
  record_num       INTEGER PRIMARY KEY   DEFAULT nextval('units_record_num_sequence'),
  unit_id          INTEGER      NOT NULL DEFAULT nextval('units_unit_id_sequence'),
  data_id          VARCHAR(100) NOT NULL,
  lore_name        VARCHAR(20),
  lore_description VARCHAR(255),
  attack_damage    REAL,
  attack_speed     REAL,
  crit_chance      REAL,
  crit_damage      REAL,
  max_health       REAL,
  movement_speed   REAL, --- Should also be responsible for dodge chance.
  armor            REAL,
  armor_shred      REAL,
  created_timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);

DROP TABLE IF EXISTS resources;
DROP SEQUENCE IF EXISTS resources_record_num_sequence;
DROP SEQUENCE IF EXISTS resources_resource_id_sequence;

CREATE SEQUENCE resources_record_num_sequence;
CREATE SEQUENCE resources_resource_id_sequence;

CREATE TABLE resources (
  record_num       INTEGER PRIMARY KEY DEFAULT nextval('resources_record_num_sequence'),
  resource_id      INTEGER NOT NULL    DEFAULT nextval('resources_resource_id_sequence'),
  lore_name        VARCHAR(30),
  lore_description VARCHAR(255),
  created_timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);


DROP TABLE IF EXISTS themes;
DROP SEQUENCE IF EXISTS themes_record_num_sequence;
DROP SEQUENCE IF EXISTS themes_theme_id_sequence;

CREATE SEQUENCE themes_record_num_sequence;
CREATE SEQUENCE themes_theme_id_sequence;

CREATE TABLE themes (
  record_num        INTEGER PRIMARY KEY DEFAULT nextval('themes_record_num_sequence'),
  theme_id          INTEGER             DEFAULT nextval('themes_theme_id_sequence'),
  name              VARCHAR(100),
  created_timestamp TIMESTAMPTZ DEFAULT CURRENT_TIMESTAMP
);
