import {
  BaseCommand,
  FileConfig,
  Arg,
  RunnableArgs,
  renderTemplate,
} from 'angel-manager';

export default class {{ plural.pascal.commandName }} extends BaseCommand {
  /**
   * Command name is used to run the command
   */
  public commandName = 'make:{{ kebab.commandName }}';

  /**
   * Description of the command
   */
  public description = 'Makes a new {{ camel.commandName }}';

  /**
   * Path to the Liquid template, relative to src/scaffolding/architecture
   */
  public templatePath = '{{ plural.kebab.commandName }}';

  /**
   * Destination path for the generated code, relative to src
   */
  public destinationPath = '{{ plural.kebab.commandName }}';

  public file: FileConfig = {
    // The name of the generated file
    name: { argName: '{{ camel.commandName }}Name', case: 'pascal' },
    // The extension of the generated file
{%- if model.staticAttributes.extension and model.staticAttributes.extension.defaultValue %}
    extension: '{{ model.staticAttributes.extension.defaultValue }}',
{%- else %}
    extension: 'tsx',
{%- endif %}
    // If true, the code will be generated inside a directory named after the file.
{%- if model.staticAttributes.subDir and model.staticAttributes.subDir.defaultValue %}
    subDir: {{ model.staticAttributes.subDir.defaultValue }},
{%- else %}
    subDir: false,
{%- endif %}
  };

  /**
   *
   * @returns an array of Arguments representing the arguments
   * to be passed to the command in the order they are defined
   */
  public args(): Arg[] {
    return [{ name: '{{ camel.commandName }}Name', type: 'string' }];
  }
{% raw %}
  public async run(args: RunnableArgs): Promise<void> {
    try {
      await renderTemplate(this, args);
    } catch (error) {
      console.error(error);
    }
  }
{% endraw -%}
}
