<?php
declare(strict_types=1);

require_once __DIR__ . '/../includes/api_auth.php';

$familyId = api_current_family_id();
$pdo = db();

$stmt = $pdo->prepare('SELECT id, family_id, max_caregiver_session, allow_indefinite, created_at, updated_at
    FROM family_settings
    WHERE family_id = ?
    LIMIT 1');
$stmt->execute([$familyId]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$row) {
    api_json([
        'success' => true,
        'settings' => [
            'family_id' => $familyId,
            'max_caregiver_session' => '90',
            'allow_indefinite' => 'no',
        ],
    ]);
}

api_json([
    'success' => true,
    'settings' => $row,
]);
