class OrderPage {
  async open() {
    return await browser.url('https://mytradingsite.com/buy');
  }

  get currentValueField() {
    return $('#current-value');
  }

  get dayBeforeValueField() {
    return $('#day-before-value');
  }

  get sellPriceValueField() {
    return $('#sell-price');
  }

  get buyPriceValueField() {
    return $('#buy-price');
  }

  async waitForMarketValuesToLoad({
    currentValue = true,
    dayBeforeValue = true,
    sellPriceValue = true,
    buyPriceValue = true
  } = {}) {
    if (currentValue) {
      await browser.waitUntil(
        async () => (await this.currentValueField.getText()) !== '-',
        {
          timeout: 30000,
          timeoutMsg: 'Current Price field should not be empty'
        }
      );
    }
    if (dayBeforeValue) {
      await browser.waitUntil(
        async () => (await this.dayBeforeValueField.getText()) !== '-',
        {
          timeout: 30000,
          timeoutMsg: 'Day Before Price field should not be empty'
        }
      );
    }
    if (sellPriceValue) {
      await browser.waitUntil(
        async () => (await this.sellPriceValueField.getText()) !== '-',
        {
          timeout: 30000,
          timeoutMsg: 'Sell Price field should not be empty'
        }
      );
    }
    if (buyPriceValue) {
      await browser.waitUntil(
        async () => (await this.buyPriceValueField.getText()) !== '-',
        {
          timeout: 30000,
          timeoutMsg: 'Buy Price field should not be empty'
        }
      );
    }
  }
}

module.exports = new OrderPage();