/**
 * @openapi
 * /api/schools:
 *   get:
 *     tags: [Schools]
 *     summary: List schools (tenant-scoped)
 *     description: Requires READ_SCHOOLS.
 *     responses:
 *       200:
 *         description: List payload.
 *         content:
 *           application/json:
 *             schema: { $ref: '#/components/schemas/ListResponse' }
 *       401: { $ref: '#/components/responses/UnauthorizedError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *   post:
 *     tags: [Schools]
 *     summary: Create a schools record
 *     description: Requires CREATE_SCHOOLS and system/organization scope.
 *     responses:
 *       200: { description: Created. }
 *       400: { $ref: '#/components/responses/ValidationError' }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 * /api/schools/{id}:
 *   put:
 *     tags: [Schools]
 *     summary: Update a schools record
 *     description: Requires UPDATE_SCHOOLS and system/organization scope.
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: string, format: uuid }
 *     responses:
 *       200: { description: Updated. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 *   delete:
 *     tags: [Schools]
 *     summary: Delete a schools record
 *     description: Requires DELETE_SCHOOLS and system/organization scope.
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema: { type: string, format: uuid }
 *     responses:
 *       200: { description: Deleted. }
 *       403: { $ref: '#/components/responses/ForbiddenError' }
 */
import express from 'express';
import { wrapAsync } from '@/api/http/request';
import permissions from '@/middlewares/check-permissions';
import controller, {
  createWithFirstCampus,
} from '@/api/controllers/schools.controller';
import { createCrudRouter } from '@/api/http/crud-router';

const router = express.Router();

// Custom atomic create (school + first campus) — must precede the generic CRUD
// router so it is matched before the generic `POST /` and `/:id` routes.
router.post(
  '/with-first-campus',
  permissions.checkPermissions('CREATE_SCHOOLS'),
  wrapAsync(createWithFirstCampus),
);

router.use(createCrudRouter(controller, { permission: 'schools' }));

export default router;
