DROP TABLE IF EXISTS devices;

CREATE TABLE devices (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  type TEXT NOT NULL,
  status TEXT NOT NULL DEFAULT 'off' CHECK (status IN ('on', 'off')),
  power INTEGER NOT NULL DEFAULT 0,
  has_wifi BOOLEAN NOT NULL DEFAULT true,
  has_alert BOOLEAN NOT NULL DEFAULT false,
  is_high_usage BOOLEAN NOT NULL DEFAULT false,
  custom_timer INTEGER,
  runtime INTEGER NOT NULL DEFAULT 0,
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

INSERT INTO devices
  (id, name, type, status, power, has_wifi, has_alert, is_high_usage, custom_timer, runtime)
VALUES
  ('1', 'Living Room TV', 'tv', 'on', 120, true, false, false, null, 3240),
  ('2', 'Gaming Console', 'gaming', 'on', 165, true, false, false, 900, 7845),
  ('3', 'Kitchen Stove', 'stove', 'off', 0, true, false, false, null, 0),
  ('4', 'Washer', 'washer', 'on', 450, true, false, false, null, 1620),
  ('5', 'Bedroom TV', 'tv', 'off', 0, true, false, false, null, 0),
  ('6', 'Office Monitor', 'tv', 'off', 0, true, false, false, null, 0);
