export interface CommandResultDTO {
  success: boolean;
  errorCode?: string;
  message?: string;
}

export class CommandResultPresenter {
  private model: CommandResultDTO | null = null;

  reset(): void {
    this.model = null;
  }

  present(): void {
    // For command use cases, if we get here, it was successful
    // The service handles errors by throwing exceptions
    this.model = { success: true };
  }

  presentSuccess(message?: string): void {
    this.model = {
      success: true,
      ...(message !== undefined && { message }),
    };
  }

  presentFailure(errorCode: string, message?: string): void {
    this.model = {
      success: false,
      errorCode,
      ...(message !== undefined && { message }),
    };
  }

  getResponseModel(): CommandResultDTO | null {
    return this.model;
  }

  get responseModel(): CommandResultDTO {
    if (!this.model) {
      throw new Error('Presenter not presented');
    }

    return this.model;
  }

  get viewModel(): CommandResultDTO {
    return this.responseModel;
  }
}