import type { DevframeNodeContext, DevframeViewHost as DevframeViewHostType } from 'devframe/types'
import { existsSync } from 'node:fs'
import { diagnostics } from './diagnostics'

export class DevframeViewHost implements DevframeViewHostType {
  /**
   * @internal
   */
  public buildStaticDirs: { baseUrl: string, distDir: string }[] = []

  constructor(
    public readonly context: DevframeNodeContext,
  ) {
  }

  hostStatic(baseUrl: string, distDir: string) {
    if (!existsSync(distDir)) {
      throw diagnostics.DF0008({ distDir })
    }

    this.buildStaticDirs.push({ baseUrl, distDir })
    this.context.host.mountStatic(baseUrl, distDir)
  }
}
