CREATE TABLE IF NOT EXISTS public.organizations (
  id VARCHAR PRIMARY KEY,
  name VARCHAR NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS public.users (
  id VARCHAR PRIMARY KEY,
  email VARCHAR UNIQUE NOT NULL,
  organization_id VARCHAR REFERENCES organizations(id),
  role VARCHAR,
  created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE IF NOT EXISTS public.customers (
  id VARCHAR PRIMARY KEY,
  organization_id VARCHAR REFERENCES organizations(id),
  first_name VARCHAR,
  last_name VARCHAR,
  email VARCHAR,
  created_at TIMESTAMP DEFAULT NOW()
);

INSERT INTO public.organizations (id, name)
VALUES ('test-org-001', 'Test Organization')
ON CONFLICT (id) DO NOTHING;

INSERT INTO public.users (id, email, organization_id, role)
VALUES ('test-admin-user', 'admin@test.com', 'test-org-001', 'admin')
ON CONFLICT (id) DO NOTHING;

INSERT INTO public.customers (id, organization_id, first_name, last_name, email)
VALUES
  ('cus_01JEMN4XZ8Y6Q3KPVWRST2FGHA', 'test-org-001', 'John', 'Doe', 'john@example.com'),
  ('cus_02JEMN4XZ8Y6Q3KPVWRST2FGHB', 'test-org-001', 'Jane', 'Smith', 'jane@example.com'),
  ('cus_03JEMN4XZ8Y6Q3KPVWRST2FGHC', 'test-org-001', 'Bob', 'Johnson', 'bob@example.com'),
  ('cus_04JEMN4XZ8Y6Q3KPVWRST2FGHD', 'test-org-001', 'Alice', 'Williams', 'alice@example.com'),
  ('cus_05JEMN4XZ8Y6Q3KPVWRST2FGHE', 'test-org-001', 'Charlie', 'Brown', 'charlie@example.com')
ON CONFLICT (id) DO NOTHING;
