<?php

class Migration_20250826041723_alter_table_resources_add_pending_payment
{
    public static function up(PDO $pdo)
    {
        $sql="INSERT INTO resources (name, slug, dataPage, label, icon, isChild, display_order) VALUES 
            ('pending_payments', 'pending_payment.php', '', 'Pending Payments', 'fa fa-bank', '', '16')
            ;
        ";
        $pdo->exec($sql);

        $roles = ['super_admin', 'admin'];
        $resources = [
            'super_admin' => ['pending_payments'],
            'admin' => ['pending_payments'],
        ];
        $actions = ['read', 'write'];
        $sql2 = '';

        foreach ($roles as $role) {
            if (isset($resources[$role])) {
                foreach ($resources[$role] as $resource) {
                    foreach ($actions as $action) {
                        $sql2 .= "
                            INSERT INTO role_resources (role_id, resource_id, action_id)
                            VALUES (
                                (SELECT id FROM roles WHERE name = '$role'),
                                (SELECT id FROM resources WHERE name = '$resource'),
                                (SELECT id FROM actions WHERE name = '$action')
                            );\n";
                    }
                }
            }
        }

        $pdo->exec($sql2);

    }

    public static function down(PDO $pdo)
    {
        
    }
}