<?php

require_once __DIR__ . '/../helpers.php';

function my_settings_repository_fetch_budget_periods(int $userId): array
{
    if ($userId <= 0) {
        return [];
    }

    return fetch_all(
        'SELECT budget_label, is_active
         FROM user_budget_periods
         WHERE user_id = ? AND is_deleted = 0 AND deleted_at IS NULL AND status = "active"
         ORDER BY COALESCE(period_start, created_at) DESC, id DESC',
        'i',
        [$userId]
    );
}

function my_settings_repository_fetch_approver_options(): array
{
    return fetch_all(
        'SELECT id, business_name, email
         FROM users
         ORDER BY business_name, email'
    );
}
