import { IImageStorage, ImageEntityType, ImageResult } from '../../../application/ports/image-storage';
import { NotFoundError } from '../../../domain/errors/not-found-error';

export class GetImageUseCase {
  constructor(private readonly imageStorage: IImageStorage) {}

  async execute(type: ImageEntityType, id: string): Promise<ImageResult> {
    const image = await this.imageStorage.readImage(type, id);
    if (!image) {
      throw new NotFoundError('Image', `${type}/${id}`);
    }
    return image;
  }
}
