-- PostgreSQL schema for iPad repair app

CREATE TABLE IF NOT EXISTS iPads (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  asset_tag TEXT NOT NULL UNIQUE,
  model TEXT NOT NULL,
  created_at TEXT DEFAULT CURRENT_TIMESTAMP,
  is_mock INTEGER DEFAULT 0
);

CREATE TABLE IF NOT EXISTS repairs (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  i_pad_id INTEGER REFERENCES iPads(id) ON DELETE CASCADE,
  repair_type TEXT NOT NULL,
  cost REAL NOT NULL,
  repair_date TEXT NOT NULL,
  is_mock INTEGER DEFAULT 0
);

-- Optional: lookup table for repair types and costs
CREATE TABLE IF NOT EXISTS repair_types (
  id SERIAL PRIMARY KEY,
  name VARCHAR(50) NOT NULL UNIQUE,
  standard_cost NUMERIC(10,2) NOT NULL
);

-- Seed repair types
INSERT INTO repair_types (name, standard_cost) VALUES
  ('Broken screen', 130.00),
  ('Broken LCD', 130.00),
  ('Broken charge port', 150.00),
  ('Broken headphone jack', 150.00),
  ('Broken volume button', 150.00),
  ('Broken home button', 150.00),
  ('Broken power button', 150.00)
ON CONFLICT (name) DO NOTHING;
