// SPDX-License-Identifier: Apache-2.0

import {type HelmExecutionBuilder} from '../../execution/helm-execution-builder.js';
import {type HelmRequest} from '../helm-request.js';
import {type TestChartOptions} from '../../model/test/test-chart-options.js';
import {TestChartOptionsBuilder} from '../../model/test/test-chart-options-builder.js';

/**
 * A request to test a Helm chart.
 */
export class ChartTestRequest implements HelmRequest {
  /**
   * Creates a new test request with the given release name and options.
   *
   * @param releaseName The name of the release.
   * @param options The options to use when testing the chart.
   */
  public constructor(
    public readonly releaseName: string,
    public readonly options: TestChartOptions = TestChartOptionsBuilder.builder().build(),
  ) {
    if (!releaseName) {
      throw new Error('releaseName must not be null');
    }
    if (releaseName.trim() === '') {
      throw new Error('releaseName must not be null or blank');
    }
    if (!options) {
      throw new Error('options must not be null');
    }
  }

  public apply(builder: HelmExecutionBuilder): void {
    builder.subcommands('test');
    this.options.apply(builder);
    builder.positional(this.releaseName);
  }
}
