create table if not exists payment_orders (
  id uuid primary key default gen_random_uuid(),
  payment_no text not null unique,
  order_id uuid not null references orders(id) on delete cascade,
  channel text not null default 'dev',
  amount integer not null default 0,
  status text not null default 'created',
  expires_at timestamptz not null default (now() + interval '30 minutes'),
  created_at timestamptz not null default now(),
  updated_at timestamptz not null default now()
);

create table if not exists admin_audit_logs (
  id uuid primary key default gen_random_uuid(),
  actor text not null default 'lite-admin',
  action text not null,
  resource text not null,
  resource_id text,
  detail jsonb not null default '{}'::jsonb,
  created_at timestamptz not null default now()
);

create index if not exists idx_payment_orders_order on payment_orders(order_id);
create index if not exists idx_payment_orders_status on payment_orders(status, created_at desc);
create index if not exists idx_admin_audit_resource on admin_audit_logs(resource, resource_id, created_at desc);
