import { Controller, Get, Param, BadRequestException } from '@nestjs/common';
import { ShootingRepo } from '../../repos/shooting.repo';
import { generateManifest } from '../../functions/generate-manifest';
import { generateManifestCustomer } from '../../functions/generate-manifest-customer';
import { assertRessourceExists } from '@/core/functions/assert';
import { CustomerRepo } from '../../repos/customer.repo';

@Controller('shootings')
export class GenerateManifest {
  constructor(
    private shootingRepo: ShootingRepo,
    private customerRepo: CustomerRepo,
  ) {}

  @Get(':id/manifest')
  async execute(@Param('id') shootingId: string) {
    const shooting = await this.shootingRepo.findById(shootingId);
    assertRessourceExists(shooting);
    return generateManifest(shooting);
  }

  @Get('customer/:customerId/manifest')
  async executeCustomer(@Param('customerId') customerId: string) {
    const customer = await this.customerRepo.findById(customerId);
    assertRessourceExists(customer);
    return generateManifestCustomer(customer);
  }
}
