export const baseUrl = process.env.STAGE == "staging" ? "https://doorman-6741-staging.twil.io": "http://localhost:8080";
export const buzzerUrl = process.env.STAGE == "staging" ? "https://buzzer-2439-staging.twil.io/buzzer-activated": "http://localhost:4500/buzzer-activated";
export const doorName = "test";
export const buzzerNumber = "6133163433";
export const key = "1234";

console.log("using URL", baseUrl, buzzerUrl);

export const waitForService = async (url: string, timeout = 30000) => {
  const start = Date.now();
  
  while (Date.now() - start < timeout) {
    try {
      await fetch(url);
      return true;
    } catch (err) {
      await new Promise(resolve => setTimeout(resolve, 1000));
    }
  }
  throw new Error(`Service at ${url} did not start within ${timeout}ms`);
};
