import { Controller, Get, Param, UseInterceptors } from '@nestjs/common';
import { ShootingRepo } from '../../repos/shooting.repo';
import { assertRessourceExists } from '@/core/functions/assert';
import { ShootingMapper } from '../../mappers/shooting.mapper';
import { Public } from '@/models/users/decorators/public-route';
import { CurrentUser } from '@/models/users/decorators/current-user';
import { User } from '@/models/users/domain/user';
import { UserActivityInterceptor } from '@/models/users/interceptors/user-activity.interceptor';
import { TrackActivity } from '@/models/users/decorators/track-activity';

@Controller('shootings')
export class GetShooting {
  constructor(private shootingRepo: ShootingRepo) {}

  @Public()
  @Get(':id')
  @UseInterceptors(UserActivityInterceptor)
  @TrackActivity('SHOOTING_VIEW')
  async execute(@Param('id') id: string, @CurrentUser() currentUser: User) {
    const shooting = await this.shootingRepo.findById(id);

    assertRessourceExists(shooting);

    const mappedShooting = ShootingMapper.toDTO(shooting, {
      includeCustomer: !!currentUser,
    });

    return mappedShooting;
  }
}
