-- members
CREATE TABLE IF NOT EXISTS members (
  id          SERIAL PRIMARY KEY,
  email       TEXT NOT NULL UNIQUE,
  first_name  TEXT NOT NULL,
  last_name   TEXT NOT NULL,
  password    TEXT NOT NULL,
  apps        TEXT[] DEFAULT '{}',
  created     TIMESTAMPTZ DEFAULT NOW()
);

-- networks
CREATE TABLE IF NOT EXISTS networks (
  id                  SERIAL PRIMARY KEY,
  name                TEXT NOT NULL,
  logo                TEXT,
  abbreviation        TEXT,
  apps                TEXT[] DEFAULT '{}',
  stripe_account_id   TEXT,
  stripe_access_token TEXT,
  created             TIMESTAMPTZ DEFAULT NOW()
);

-- edges (member in network)
CREATE TABLE IF NOT EXISTS member_network (
  id         SERIAL PRIMARY KEY,
  member_id  INTEGER REFERENCES members(id),
  network_id INTEGER REFERENCES networks(id),
  type       TEXT NOT NULL DEFAULT 'IN',
  created    TIMESTAMPTZ DEFAULT NOW(),
  UNIQUE(member_id, network_id)
);

-- create schema
CREATE SCHEMA IF NOT EXISTS org_1;

-- join form table
CREATE TABLE IF NOT EXISTS org_1.join_form (
  id        SERIAL PRIMARY KEY,
  fname     TEXT NOT NULL,
  lname     TEXT NOT NULL,
  email     TEXT NOT NULL,
  phone     TEXT,
  county    TEXT,
  time      TIMESTAMPTZ DEFAULT NOW()
);

-- contact form table
CREATE TABLE IF NOT EXISTS org_1.contact_form (
  id        SERIAL PRIMARY KEY,
  fname     TEXT NOT NULL,
  lname     TEXT NOT NULL,
  email     TEXT NOT NULL,
  phone     TEXT,
  message   TEXT,
  county    TEXT,
  time      TIMESTAMPTZ DEFAULT NOW()
);