<?php
declare(strict_types=1);
require_once __DIR__ . '/../../../app/Models/Coa.php';
require_once __DIR__ . '/../../../app/Config/functions.php';
require_login();

header('Content-Type: application/json');
$model = new Coa();

$data = [
  'account_code' => $_POST['account_code'] ?? '',
  'account_name' => $_POST['account_name'] ?? '',
  'account_type' => $_POST['account_type'] ?? '',
  'parent_account' => $_POST['parent_account'] ?? null,
  'description' => $_POST['description'] ?? '',
  'status' => $_POST['status'] ?? 'active'
];

$success = $model->create($data);

echo json_encode([
  'success' => $success,
  'message' => $success ? 'Account added successfully!' : 'Failed to add account.'
]);
