<?php

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

declare(strict_types=1);

namespace Dagger;

/**
 * Function represents a resolver provided by a Module.
 *
 * A function always evaluates against a parent object and is given a set of named arguments.
 */
class Function_ extends Client\AbstractObject implements Client\IdAble
{
    public function args(): array
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('args');
        return (array)$this->queryLeaf($leafQueryBuilder, 'args');
    }

    public function description(): string
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('description');
        return (string)$this->queryLeaf($leafQueryBuilder, 'description');
    }

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

    public function name(): string
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('name');
        return (string)$this->queryLeaf($leafQueryBuilder, 'name');
    }

    public function returnType(): TypeDef
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('returnType');
        return new \Dagger\TypeDef($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }

    /**
     * Returns the function with the provided argument
     */
    public function withArg(
        string $name,
        TypeDefId|TypeDef $typeDef,
        ?string $description = '',
        ?Json $defaultValue = null,
    ): Function_
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('withArg');
        $innerQueryBuilder->setArgument('name', $name);
        $innerQueryBuilder->setArgument('typeDef', $typeDef);
        if (null !== $description) {
        $innerQueryBuilder->setArgument('description', $description);
        }
        if (null !== $defaultValue) {
        $innerQueryBuilder->setArgument('defaultValue', $defaultValue);
        }
        return new \Dagger\Function_($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }

    /**
     * Returns the function with the given doc string.
     */
    public function withDescription(string $description): Function_
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('withDescription');
        $innerQueryBuilder->setArgument('description', $description);
        return new \Dagger\Function_($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }
}
