import { Browser, chromium, LaunchOptions, Page } from 'playwright';

export async function launchBrowserWithISPProxy(country?: string, ip?: string): Promise<{ browser: Browser; page: Page }> {
  const proxyServer = 'http://brd.superproxy.io:33335';
  let username: string = "";
  ip ? username = `brd-customer-hl_bc33aa9b-zone-isp_proxy_perifit-country-${country}-ip-${ip}` : username = `brd-customer-hl_bc33aa9b-zone-isp_proxy_perifit-country-${country}`;

  const password = 'ckyhmuomd5si';

  const options: LaunchOptions = {
    proxy: {
      server: proxyServer,
      username,
      password,
    },
    headless: true,
  };

  const browser = await chromium.launch(options);
  const page = await browser.newPage({ ignoreHTTPSErrors: true });
  return { browser, page };
}