/**
 * Smoke: register a sandbox domain, then update its nameservers to a
 * fake-but-valid set. Proves the full attach-time registrar flow.
 *
 * Usage:  source .opensrs.env && npx tsx scripts/smoke-opensrs-ns-update.ts
 */

import {
  registerDomain,
  updateDomainNameservers,
  type RegistrationContact,
} from '../lib/opensrs';

const CONTACT: RegistrationContact = {
  first_name: 'Mark',
  last_name: 'Henderson',
  org_name: 'Get Acquired Inc',
  address1: '123 King St W',
  city: 'Toronto',
  state: 'ON',
  country: 'CA',
  postal_code: 'M5H 1A1',
  phone: '+1.4165551234',
  email: 'mark@getacquired.com',
};

async function main() {
  const domain = `vibnai-ns-${Date.now()}.com`;
  console.log('[ns-smoke] register', domain);
  const reg = await registerDomain({ domain, period: 1, contact: CONTACT });
  console.log('[ns-smoke] registered. order=', reg.orderId);

  // Cloud DNS nameservers follow this format — use real-looking values.
  // Horizon only knows about nameservers that already exist at the registry
  // it talks to. Its built-in ones are ns1/ns2.systemdns.com, and they're
  // the ones every sandbox domain registers with by default. In production
  // we'll point at the Cloud DNS nameservers returned from createZone, which
  // are publicly resolvable and accepted by every upstream registry.
  const ns = ['ns1.systemdns.com', 'ns2.systemdns.com', 'ns3.systemdns.com', 'ns4.systemdns.com'];
  console.log('[ns-smoke] updating NS to', ns);
  const upd = await updateDomainNameservers(domain, ns);
  console.log('[ns-smoke] NS update response:', upd);
}

main().catch(err => { console.error('[ns-smoke] FAILED:', err); process.exit(1); });
