import { createParamDecorator, ExecutionContext } from '@nestjs/common'

import type { UploadRequest } from './upload.types'

export const UploadedFileData = createParamDecorator((_data: unknown, ctx: ExecutionContext) => {
  const req = ctx.switchToHttp().getRequest<UploadRequest>()
  if (!req.uploadedFileData) {
    throw new Error('Decorator @UploadedFileData must be used with @UploadGuard')
  }

  return req.uploadedFileData
})
