import VoiceResponse from 'twilio/lib/twiml/VoiceResponse';
import { InfoResponseClient } from '../../../doorman-api/src/functions/api/door/info';

export function doorOpenTwiml(config: InfoResponseClient): VoiceResponse {
  const twiml = new Twilio.twiml.VoiceResponse();
  
  // play audio
  twiml.play('https://buzzer-2439-prod.twil.io/buzzing_up_boosted.mp3');
  
  // press digit
  twiml.play({ digits: config.pressKey }); // configured in doorman what button to click and passed into this function

  // pause
  twiml.pause({ length: 1 });

  // exit
  twiml.hangup();

  // @ts-ignore
  return twiml;
}

export function dialFallbackTwiml(config: InfoResponseClient): VoiceResponse {
  const twiml = new Twilio.twiml.VoiceResponse();

  let dial = twiml.dial({
    timeLimit: 20, 
    timeout: 20
  });

  config.fallbackNumbers.forEach(number => {
    dial.number(number);
  });

  // @ts-ignore
  return twiml;
}
