<?php
declare(strict_types=1);

return function (\App\Core\Database $db): void {
    $now = date('Y-m-d H:i:s');

    $treasuries = [
        [
            'code'         => 'MAIN',
            'name_ar'      => 'الخزنة الرئيسية',
            'name_en'      => 'Main Treasury',
            'type'         => 'main',
            'account_code' => '12060101',
            'branch_id'    => null,
            'is_active'    => 1,
            'created_at'   => $now,
            'updated_at'   => $now,
        ],
        [
            'code'         => 'SUB_SA',
            'name_ar'      => 'خزنة الأنشطة الرياضية',
            'name_en'      => 'Sports Activities Sub-Treasury',
            'type'         => 'sub',
            'account_code' => '12060102',
            'branch_id'    => null,
            'is_active'    => 1,
            'created_at'   => $now,
            'updated_at'   => $now,
        ],
    ];

    foreach ($treasuries as $treasury) {
        $exists = $db->selectOne("SELECT 1 FROM treasuries WHERE code = ?", [$treasury['code']]);
        if (!$exists) {
            $db->insert('treasuries', $treasury);
        }
    }
};
