<?php
declare(strict_types=1);

require_once __DIR__ . '/db.php';

/**
 * Assign a role to a user
 */
function assignRoleToUser(
    int $userId,
    int $roleId,
    ?int $companyId
): void {
    $db = db();

    $stmt = $db->prepare("
        INSERT IGNORE INTO user_roles (user_id, role_id, company_id)
        VALUES (:user_id, :role_id, :company_id)
    ");

    $stmt->execute([
        'user_id'    => $userId,
        'role_id'    => $roleId,
        'company_id' => $companyId
    ]);
}
