<?php

/**
 * This class has been generated by dagger-php-sdk. DO NOT EDIT.
 */

declare(strict_types=1);

namespace Dagger;

class JsonValue extends Client\AbstractObject implements Client\IdAble
{
    /**
     * Decode an array from json
     */
    public function asArray(): array
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('asArray');
        return (array)$this->queryLeaf($leafQueryBuilder, 'asArray');
    }

    /**
     * Decode a boolean from json
     */
    public function asBoolean(): bool
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('asBoolean');
        return (bool)$this->queryLeaf($leafQueryBuilder, 'asBoolean');
    }

    /**
     * Decode an integer from json
     */
    public function asInteger(): int
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('asInteger');
        return (int)$this->queryLeaf($leafQueryBuilder, 'asInteger');
    }

    /**
     * Decode a string from json
     */
    public function asString(): string
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('asString');
        return (string)$this->queryLeaf($leafQueryBuilder, 'asString');
    }

    /**
     * Return the value encoded as json
     */
    public function contents(?bool $pretty = false, ?string $indent = '  '): Json
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('contents');
        if (null !== $pretty) {
        $leafQueryBuilder->setArgument('pretty', $pretty);
        }
        if (null !== $indent) {
        $leafQueryBuilder->setArgument('indent', $indent);
        }
        return new \Dagger\Json((string)$this->queryLeaf($leafQueryBuilder, 'contents'));
    }

    /**
     * Lookup the field at the given path, and return its value.
     */
    public function field(array $path): JsonValue
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('field');
        $innerQueryBuilder->setArgument('path', $path);
        return new \Dagger\JsonValue($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }

    /**
     * List fields of the encoded object
     */
    public function fields(): array
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('fields');
        return (array)$this->queryLeaf($leafQueryBuilder, 'fields');
    }

    /**
     * A unique identifier for this JSONValue.
     */
    public function id(): JsonValueId
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('id');
        return new \Dagger\JsonValueId((string)$this->queryLeaf($leafQueryBuilder, 'id'));
    }

    /**
     * Encode a boolean to json
     */
    public function newBoolean(bool $value): JsonValue
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('newBoolean');
        $innerQueryBuilder->setArgument('value', $value);
        return new \Dagger\JsonValue($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }

    /**
     * Encode an integer to json
     */
    public function newInteger(int $value): JsonValue
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('newInteger');
        $innerQueryBuilder->setArgument('value', $value);
        return new \Dagger\JsonValue($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }

    /**
     * Encode a string to json
     */
    public function newString(string $value): JsonValue
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('newString');
        $innerQueryBuilder->setArgument('value', $value);
        return new \Dagger\JsonValue($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }

    /**
     * Return a new json value, decoded from the given content
     */
    public function withContents(Json $contents): JsonValue
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('withContents');
        $innerQueryBuilder->setArgument('contents', $contents);
        return new \Dagger\JsonValue($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }

    /**
     * Set a new field at the given path
     */
    public function withField(array $path, JsonValueId|JsonValue $value): JsonValue
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('withField');
        $innerQueryBuilder->setArgument('path', $path);
        $innerQueryBuilder->setArgument('value', $value);
        return new \Dagger\JsonValue($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }
}
