<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/_bootstrap.php';

golder_require_method('GET');
$ctx = golder_api_auth('desktop_sync');
$customer = sync_api_require_profile_sync_customer((int)($ctx['customer_id'] ?? 0));

try {
    $tenant = golder_tenant_pdo_from_customer($customer);
    sync_api_ensure_deleted_profiles_table($tenant);

    // Aktif profiller
    $profiles = $tenant->query("SELECT id, name, is_active FROM profiles WHERE COALESCE(is_deleted, 0) = 0")->fetchAll() ?: [];
    
    // Silinmiş profiller
    $deleted = $tenant->query("SELECT profile_id FROM deleted_profiles")->fetchAll() ?: [];

    golder_json_response([
        'status' => 'ok', 
        'profiles' => $profiles, 
        'deleted_profiles' => $deleted
    ]);
} catch (Throwable $e) {
    sync_api_json_error(500, 'CATALOG_ERROR', $e->getMessage());
}

