import { omit } from 'lodash';
import { RequestCookie } from 'next/dist/compiled/@edge-runtime/cookies';
import { NextRequest } from 'next/server';

import { authorizationMiddleware } from '../../middlewares/auth.middleware';
import { validationErrorHandler } from '../../middlewares/error-handler.middleware';

const routeHandler = async (req: NextRequest, requestCookie: RequestCookie) => {
  const parsedData = JSON.parse(requestCookie.value);

  return new Response(JSON.stringify(omit(parsedData, 'token')), {
    headers: { 'Content-Type': 'application/json' },
  });
};

export const GET = validationErrorHandler(
  authorizationMiddleware(routeHandler, 'corporate__token'),
);
