import { applyDecorators, UseGuards, UseInterceptors } from '@nestjs/common';
import { PermissionGuard } from '../auth/permission.guard';
import { RequirePermission, type PermissionScopeOptions } from '../auth/permission.decorator';
import { AuditMutation, type AuditMutationMetadata } from './audit-mutation.decorator';
import { AuditMutationInterceptor } from './audit-mutation.interceptor';

export function ProtectedMutation(
  permission: string,
  scope: PermissionScopeOptions,
  audit: AuditMutationMetadata,
) {
  return applyDecorators(
    UseGuards(PermissionGuard),
    RequirePermission(permission, scope),
    UseInterceptors(AuditMutationInterceptor),
    AuditMutation(audit),
  );
}
