<?php
require_once __DIR__ . '/../../engine/engine.php';
header('Content-Type: application/json; charset=utf-8');

try {
	$name = isset($_POST['name']) ? trim($_POST['name']) : '';
	$currency = isset($_POST['currency']) ? trim($_POST['currency']) : '';
	if ($name === '') { http_response_code(400); echo json_encode(['success'=>false,'error'=>"Feld 'name' ist erforderlich."]); exit; }

	$stmt = $pdo->prepare("INSERT INTO depot_portfolios (name, currency) VALUES (:name, :currency)");
	$stmt->execute([':name'=>$name, ':currency'=>$currency]);

	echo json_encode(['success'=>true]);
} catch (Throwable $e) {
	http_response_code(500);
	echo json_encode(['success'=>false,'error'=>'DB-Fehler: '.$e->getMessage()]);
}