import { i18n } from './i18n'
import { sdk } from './sdk'
import { uiPort } from './utils'

export const main = sdk.setupMain(async ({ effects }) => {
  console.info(i18n('Starting YouTube Summarizer...'))

  return sdk.Daemons.of(effects).addDaemon('primary', {
    subcontainer: await sdk.SubContainer.of(
      effects,
      { imageId: 'main' },
      sdk.Mounts.of().mountVolume({
        volumeId: 'main',
        subpath: null,
        mountpoint: '/data',
        readonly: false,
      }),
      'youtube-summarizer-sub',
    ),
    exec: {
      command: [
        'dumb-init',
        '--',
        '/usr/local/bin/docker_entrypoint.sh',
      ],
    },
    ready: {
      display: i18n('Web Interface'),
      fn: () =>
        sdk.healthCheck.checkPortListening(effects, uiPort, {
          successMessage: i18n('YouTube Summarizer is ready'),
          errorMessage: i18n('YouTube Summarizer is not responding'),
        }),
    },
    requires: [],
  })
})
