import { FioFeeResponse } from '../../entities/FioFeeResponse'
import { Constants } from '../../utils/constants'
import { Query } from './Query'
import { validationRules } from '../../utils/validation'

export class GetFee extends Query<FioFeeResponse> {
  public ENDPOINT: string = 'chain/get_fee'
  public endPoint: string
  public fioAddress: string

  constructor(endPoint: string, fioAddress: string = '') {
    super()
    this.endPoint = endPoint
    this.fioAddress = fioAddress

    if (Constants.feeNoAddressOperation.findIndex((element) => element === endPoint) > -1 && fioAddress.length > 0) {
      throw new Error('End point ' + endPoint + ' should not have any fio address, when requesting fee')
    }

    if (fioAddress) {
      this.validationData = { fioAddress }
      this.validationRules = validationRules.getFee
    }
  }

  public getData() {
    const data = { end_point: this.endPoint, fio_address: this.fioAddress || null }
    return data
  }
}
