PRAGMA foreign_keys = OFF;
DROP TABLE IF EXISTS tickets;
DROP TABLE IF EXISTS accounts;
PRAGMA foreign_keys = ON;

CREATE TABLE accounts (
  id INTEGER PRIMARY KEY,
  email TEXT NOT NULL UNIQUE,
  display_name TEXT,
  is_active INTEGER NOT NULL,
  created_at TEXT NOT NULL
);

CREATE TABLE tickets (
  id INTEGER PRIMARY KEY,
  account_id INTEGER NOT NULL,
  title TEXT NOT NULL,
  status TEXT NOT NULL,
  notes TEXT,
  amount_cents INTEGER NOT NULL,
  created_at TEXT NOT NULL,
  FOREIGN KEY (account_id) REFERENCES accounts(id)
);

INSERT INTO accounts (id, email, display_name, is_active, created_at) VALUES
  (1, 'alice@example.com', 'Alice', 1, '2026-03-01T08:30:00Z'),
  (2, 'maria@example.com', 'Máría', 0, '2026-03-10T09:45:00Z'),
  (3, 'zhang@example.com', '张敏', 1, '2026-03-15T12:00:00Z');

INSERT INTO tickets (id, account_id, title, status, notes, amount_cents, created_at) VALUES
  (101, 1, 'login timeout', 'open', NULL, 0, '2026-03-20T10:00:00Z'),
  (102, 1, 'csv export mismatch', 'closed', 'fixed after re-run', 1500, '2026-03-21T11:15:00Z'),
  (103, 2, '权限验证', 'open', 'needs DBA review', 300, '2026-03-22T15:30:00Z'),
  (104, 3, 'emoji smoke 😀', 'open', NULL, 42, '2026-03-23T07:05:00Z');
