<?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
{
    /**
     * Arguments accepted by the function, if any.
     */
    public function args(): array
    {
        $leafQueryBuilder = new \Dagger\Client\QueryBuilder('args');
        return (array)$this->queryLeaf($leafQueryBuilder, 'args');
    }

    /**
     * A doc string for the function, if any.
     */
    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'));
    }

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

    /**
     * The type returned by the function.
     */
    public function returnType(): TypeDef
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('returnType');
        return new \Dagger\TypeDef($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }

    /**
     * The location of this function declaration.
     */
    public function sourceMap(): SourceMap
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('sourceMap');
        return new \Dagger\SourceMap($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,
        ?string $defaultPath = '',
        ?array $ignore = null,
        SourceMapId|SourceMap|null $sourceMap = 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);
        }
        if (null !== $defaultPath) {
        $innerQueryBuilder->setArgument('defaultPath', $defaultPath);
        }
        if (null !== $ignore) {
        $innerQueryBuilder->setArgument('ignore', $ignore);
        }
        if (null !== $sourceMap) {
        $innerQueryBuilder->setArgument('sourceMap', $sourceMap);
        }
        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));
    }

    /**
     * Returns the function with the given source map.
     */
    public function withSourceMap(SourceMapId|SourceMap $sourceMap): Function_
    {
        $innerQueryBuilder = new \Dagger\Client\QueryBuilder('withSourceMap');
        $innerQueryBuilder->setArgument('sourceMap', $sourceMap);
        return new \Dagger\Function_($this->client, $this->queryBuilderChain->chain($innerQueryBuilder));
    }
}
