// start/middleware/AllowedMethods.ts
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'

export default class AllowedMethods {
  public async handle({ request, response }: HttpContextContract, next: () => Promise<void>) {
    const allowed = ['GET', 'POST', 'HEAD', 'OPTIONS']

    if (!allowed.includes(request.method())) {
      return response.methodNotAllowed({
        message: `Method ${request.method()} not allowed.`,
      })
    }

    await next()
  }
}