import { Controller, Get, Header, Param, StreamableFile } from '@nestjs/common';
import { ApiExcludeController } from '@nestjs/swagger';
import { Public } from '../auth/decorators/auth.decorators';
import { UltramsgMediaService } from './ultramsg-media.service';

@ApiExcludeController()
@Public()
@Controller('ultramsg/media')
export class UltramsgMediaController {
  constructor(private readonly media: UltramsgMediaService) {}

  @Get(':fileId')
  @Header('Cache-Control', 'public, max-age=86400')
  getMedia(@Param('fileId') fileId: string): StreamableFile {
    const file = this.media.open(fileId);
    return new StreamableFile(file.stream, { type: file.mime, disposition: 'inline' });
  }
}
