import { Injectable } from '@nestjs/common';
import { Command, CommandRunner } from 'nest-commander';
import { AuthService } from './auth/auth.service';

@Injectable()
@Command({ name: 'setup-admin', description: 'Set up the first admin user' })
export class SetupAdminCommand extends CommandRunner {
  constructor(private readonly authService: AuthService) {
    super();
  }

  async run(passedParams: string[]): Promise<void> {
    if (passedParams.length < 1) {
      console.error('Please provide a user UID');
      return;
    }

    const uid = passedParams[0];

    try {
      await this.authService.setUserRole(uid, 'admin');
      console.log(`User ${uid} has been set as admin`);
    } catch (error) {
      console.error('Error setting admin role:', error);
    }
  }
}
