import { Transmit } from '@adonisjs/transmit-client'
import { Service } from '../core/Service.js'

export default class TransmitService extends Service {
  static override key = 'api-service/transmit'

  transmit?: Transmit

  protected url: string

  /**
   * @param url - The URL of the API server.
   */
  constructor(url: string) {
    super()
    this.url = url
  }

  protected override async onCreate(): Promise<void> {
    this.transmit = new Transmit({
      baseUrl: this.url,
    })
  }

  protected override async onDestroy(): Promise<void> {
    this.transmit?.close()
  }
}
