<?php

if (! defined('ABSPATH')) {
    exit;
} class PufferGo_Json_Object_Codec
{
    public static function normalize_generate_block_payload(array $payload)
    {
        if (isset($payload['blockCapability']) && is_array($payload['blockCapability'])) {
            $payload['blockCapability'] = self::normalize_block_capability($payload['blockCapability']);
        }

return $payload;
    }

    public static function normalize_block_capability(array $capability)
    {
        if (! array_key_exists('rules', $capability)) {
            $capability['rules'] = new stdClass();

            return $capability;
        } $rules = $capability['rules'];

        if (is_array($rules) && 0 === count($rules)) {
            $capability['rules'] = new stdClass();
        } elseif (null === $rules) {
            $capability['rules'] = new stdClass();
        }

return $capability;
    }

    public static function normalize_workflow_jobs(array $jobs)
    {
        foreach ($jobs as $i => $job) {
            if (! is_array($job)) {
                continue;
            }

if (isset($job['payload']) && is_array($job['payload'])) {
                $jobs[ $i ]['payload'] = self::normalize_generate_block_payload($job['payload']);
            }
        }

return $jobs;
    }
}
