import { Inject, Injectable, NotFoundException } from '@nestjs/common'
import { DeleteVersionCommand } from './delete-version.command'
import { AppVersionRepository, APP_VERSION_REPOSITORY } from '@/domain/repositories/app-version.repository'

@Injectable()
export class DeleteVersionHandler {
  constructor(
    @Inject(APP_VERSION_REPOSITORY)
    private readonly appVersionRepository: AppVersionRepository,
  ) {}

  async execute(command: DeleteVersionCommand): Promise<void> {
    const version = await this.appVersionRepository.findById(command.id)

    if (!version) {
      throw new NotFoundException(`Version with ID ${command.id} not found`)
    }

    await this.appVersionRepository.delete(command.id)
  }
}
