import { CliLeaf, CliStringInput } from '@alwaysai/alwayscli';
import { generateProductionDeviceFunc } from '../components/device';
import { ALWAYSAI_SHOW_HIDDEN } from '../environment';
import { echo } from '../util/echo';
import logSymbols = require('log-symbols');

const generateProductionDeviceCliLeaf = () =>
  CliLeaf({
    name: 'generate-production-device',
    description: 'Generate a new production device',
    hidden: !ALWAYSAI_SHOW_HIDDEN,
    namedInputs: {
      name: CliStringInput({
        description: 'The device name. For example, "Raspberry Pi"',
        required: true,
        placeholder: '<device_name>'
      }),
      description: CliStringInput({
        description: 'A detailed description of the device',
        required: false
      })
    },
    async action(_, { name, description }) {
      echo(
        `${logSymbols.warning} The generate-production-device command is deprecated and will be removed in a future release. Please plan to move to the new alwaysAI Remote Deployment provisioning workflow. Contact alwaysAI support for assistance.`
      );
      await generateProductionDeviceFunc({ name, description });
    }
  });

export const generateProductionDevice = generateProductionDeviceCliLeaf();
