<?php

class Migration_20250212012520_update_role_permission
{
    public static function up(PDO $pdo)
    {
        $roles = [
            'super_admin' => ['admin_panel', 'admin_setup', 'dashboard', 'my_iis', 'my_properties', 'property_builder', 'integrations', 'my_roles', 'users', 'visitors', 'command_center', 'events', 'settings'], 
            'admin' => ['dealer_setup', 'dashboard', 'my_iis', 'my_properties', 'property_builder', 'integrations', 'my_roles', 'users', 'visitors', 'command_center', 'events', 'settings'],
            'dealer' => ['dashboard', 'my_iis', 'my_properties', 'property_builder', 'integrations', 'my_roles', 'users', 'visitors', 'command_center', 'events', 'settings'],
            'sub_dealer' => ['property_builder','my_roles', 'users', 'visitors', 'command_center', 'events', 'settings'],
            'organization admin' => ['property_builder', 'users', 'visitors'],
            'property admin' => ['property_builder', 'users', 'visitors'],
            'user' => ['visitors']
        ];
        $actions = ['delete'];
        $sql = '';

        foreach ($roles as $role => $resources) {
            foreach ($resources as $resource) {
                foreach ($actions as $action) {
                    $sql .= "
                        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($sql);

    }

    public static function down(PDO $pdo)
    {

    }
}