import browser from 'webextension-polyfill'

const HOST_NAME = 'org.gdown.nativehost'

export type NativeAddUriPayload = {
  url: string
  rpcPort: number
  rpcSecret: string
  referer?: string
  cookie?: string
  userAgent?: string
  authorization?: string
  proxy?: string
  split?: number
  out?: string
  dir?: string
  extractor?: string
  format?: string
}

export async function nativeAddUri(options: NativeAddUriPayload): Promise<any> {
  return browser.runtime.sendNativeMessage(HOST_NAME, {
    action: 'addUri',
    ...options,
  })
}

export async function nativeFocus(): Promise<any> {
  return browser.runtime.sendNativeMessage(HOST_NAME, { action: 'focus' })
}
