// src/server/types/fastify.d.ts
// Global type declarations for Fastify instance extensions

import 'fastify';
import { HttpError } from '@fastify/sensible';
import { FastifyRequest, FastifyReply } from 'fastify';

declare module 'fastify' {
  interface FastifyInstance {
    // Метод проверки прав (RBAC) - возвращает middleware функцию
    can(permission: string): (request: FastifyRequest, reply: FastifyReply) => boolean;
    
    // Метод проверки прав (RBAC) - возвращает middleware функцию
    canAny(...permissions: string[]): (request: FastifyRequest, reply: FastifyReply) => boolean;
    
    // Метод проверки прав (RBAC) - возвращает middleware функцию
    canAll(...permissions: string[]): (request: FastifyRequest, reply: FastifyReply) => boolean;
    
    // Объект ошибок
    httpErrors: {
      forbidden(message?: string): HttpError;
      badRequest(message?: string): HttpError;
      notFound(message?: string): HttpError;
      unauthorized(message?: string): HttpError;
      internalServerError(message?: string): HttpError;
    };
  }
}
