// Code generated by Fern. DO NOT EDIT.

package tasks

import (
	context "context"
	v2 "github.com/anduril/lattice-sdk-go/v2"
	core "github.com/anduril/lattice-sdk-go/v2/core"
	internal "github.com/anduril/lattice-sdk-go/v2/internal"
	option "github.com/anduril/lattice-sdk-go/v2/option"
	http "net/http"
)

type Client struct {
	WithRawResponse *RawClient

	baseURL string
	caller  *internal.Caller
	header  http.Header
}

func NewClient(opts ...option.RequestOption) *Client {
	options := core.NewRequestOptions(opts...)
	return &Client{
		WithRawResponse: NewRawClient(options),
		baseURL:         options.BaseURL,
		caller: internal.NewCaller(
			&internal.CallerParams{
				Client:      options.HTTPClient,
				MaxAttempts: options.MaxAttempts,
			},
		),
		header: options.ToHeader(),
	}
}

// Submit a request to create a task and schedule it for delivery. Tasks, once delivered, will
// be asynchronously updated by their destined agent.
func (c *Client) CreateTask(
	ctx context.Context,
	request *v2.TaskCreation,
	opts ...option.RequestOption,
) (*v2.Task, error) {
	response, err := c.WithRawResponse.CreateTask(
		ctx,
		request,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

func (c *Client) GetTask(
	ctx context.Context,
	// ID of task to return
	taskID string,
	opts ...option.RequestOption,
) (*v2.Task, error) {
	response, err := c.WithRawResponse.GetTask(
		ctx,
		taskID,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Update the status of a task.
func (c *Client) UpdateTaskStatus(
	ctx context.Context,
	// ID of task to update status of
	taskID string,
	request *v2.TaskStatusUpdate,
	opts ...option.RequestOption,
) (*v2.Task, error) {
	response, err := c.WithRawResponse.UpdateTaskStatus(
		ctx,
		taskID,
		request,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// Query for tasks by a specified search criteria.
func (c *Client) QueryTasks(
	ctx context.Context,
	request *v2.TaskQuery,
	opts ...option.RequestOption,
) (*v2.TaskQueryResults, error) {
	response, err := c.WithRawResponse.QueryTasks(
		ctx,
		request,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}

// This is a long polling API that will block until a new task is ready for delivery. If no new task is
// available then the server will hold on to your request for up to 5 minutes, after that 5 minute timeout
// period you will be expected to reinitiate a new request.
func (c *Client) ListenAsAgent(
	ctx context.Context,
	request *v2.AgentListener,
	opts ...option.RequestOption,
) (*v2.AgentRequest, error) {
	response, err := c.WithRawResponse.ListenAsAgent(
		ctx,
		request,
		opts...,
	)
	if err != nil {
		return nil, err
	}
	return response.Body, nil
}
