<?php
// POST /api/projects/section_create.php
require_once __DIR__ . '/../config/db.php';
require_once __DIR__ . '/../config/auth.php';

$user = requireAuth();
$db   = getDB();

$projectId = (int)post('project_id', 0);
$name      = trim(post('name', ''));

if (!$projectId) apiError('Project ID required.', 422);
if (!$name)      apiError('Section name required.', 422);

$db->prepare("INSERT INTO project_sections (project_id, name, description, sort_order, created_by) VALUES (?, ?, ?, ?, ?)")
   ->execute([$projectId, $name, post('description'), post('sort_order', 0), $user['id']]);

apiSuccess(['id' => (int)$db->lastInsertId()], 'Section created.', 201);
