// Code generated by dagger. DO NOT EDIT.

package dagger

import (
	"context"
	"encoding/json"

	"github.com/dagger/querybuilder"
)

// Retrieve the binding value, as type K3S
func (r *Binding) AsK3S() *K3S { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L41)
	q := r.query.Select("asK3S")

	return &K3S{
		query: q,
	}
}

// Create or update a binding of type K3S in the environment
func (r *Env) WithK3SInput(name string, value *K3S, description string) *Env { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L41)
	assertNotNil("value", value)
	q := r.query.Select("withK3SInput")
	q = q.Arg("name", name)
	q = q.Arg("value", value)
	q = q.Arg("description", description)

	return &Env{
		query: q,
	}
}

// Declare a desired K3S output to be assigned in the environment
func (r *Env) WithK3SOutput(name string, description string) *Env { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L41)
	q := r.query.Select("withK3SOutput")
	q = q.Arg("name", name)
	q = q.Arg("description", description)

	return &Env{
		query: q,
	}
}

type K3S struct { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L41)
	query *querybuilder.Selection

	id *ID
}
type WithK3SFunc func(r *K3S) *K3S

// With calls the provided function with current K3S.
//
// This is useful for reusability and readability by not breaking the calling chain.
func (r *K3S) With(f WithK3SFunc) *K3S {
	return f(r)
}

func (r *K3S) WithGraphQLQuery(q *querybuilder.Selection) *K3S {
	return &K3S{
		query: q,
	}
}

// K3SConfigOpts contains options for K3S.Config
type K3SConfigOpts struct {
	Local bool // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L114)
}

// returns the config file for the k3s cluster
func (r *K3S) Config(opts ...K3SConfigOpts) *File { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L111)
	q := r.query.Select("config")
	for i := len(opts) - 1; i >= 0; i-- {
		// `local` optional argument
		if !querybuilder.IsZeroValue(opts[i].Local) {
			q = q.Arg("local", opts[i].Local)
		}
	}

	return &File{
		query: q,
	}
}

func (r *K3S) Container() *Container { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L48)
	q := r.query.Select("container")

	return &Container{
		query: q,
	}
}

// A unique identifier for this K3S.
func (r *K3S) ID(ctx context.Context) (ID, error) {
	if r.id != nil {
		return *r.id, nil
	}
	q := r.query.Select("id")

	var response ID

	q = q.Bind(&response)
	return response, q.Execute(ctx)
}

// XXX_GraphQLType is an internal function. It returns the native GraphQL type name
func (r *K3S) XXX_GraphQLType() string {
	return "K3S"
}

// XXX_GraphQLIDType is an internal function. It returns the native GraphQL type name for the ID of this object
func (r *K3S) XXX_GraphQLIDType() string {
	return "ID"
}

// XXX_GraphQLID is an internal function. It returns the underlying type ID
func (r *K3S) XXX_GraphQLID(ctx context.Context) (string, error) {
	id, err := r.ID(ctx)
	if err != nil {
		return "", err
	}
	return string(id), nil
}

func (r *K3S) MarshalJSON() ([]byte, error) {
	id, err := r.ID(marshalCtx)
	if err != nil {
		return nil, err
	}
	return json.Marshal(id)
}
func (r *K3S) UnmarshalJSON(bs []byte) error {
	var id string
	err := json.Unmarshal(bs, &id)
	if err != nil {
		return err
	}
	*r = K3S{query: selectNode(dag.query, id, "K3S")}
	return nil
}

// runs k9s on the target k3s cluster
func (r *K3S) Kns() *Container { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L147)
	q := r.query.Select("kns")

	return &Container{
		query: q,
	}
}

// runs kubectl on the target k3s cluster
func (r *K3S) Kubectl(args string) *Container { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L135)
	q := r.query.Select("kubectl")
	q = q.Arg("args", args)

	return &Container{
		query: q,
	}
}

// Returns a newly initialized kind cluster
func (r *K3S) Server() *Service { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L92)
	q := r.query.Select("server")

	return &Service{
		query: q,
	}
}

// Returns a newly initialized kind cluster
func (r *K3S) WithContainer(c *Container) *K3S { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L105)
	assertNotNil("c", c)
	q := r.query.Select("withContainer")
	q = q.Arg("c", c)

	return &K3S{
		query: q,
	}
}

// AsNode returns this K3S as a Node.
// This is a local type conversion — no GraphQL call.
func (r *K3S) AsNode() Node {
	return &NodeClient{
		query: r.query,
	}
}

// K3SOpts contains options for Query.K3S
type K3SOpts struct {

	// Default: "rancher/k3s:latest"
	Image string // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L55)
	//
	// keeps the state of the cluster (not recommended).
	//
	KeepState bool // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L60)
}

// Runs a k3s server than can be accessed both locally and in your pipelines
func (r *Query) K3S(name string, opts ...K3SOpts) *K3S { // k3s (https://github.com/marcosnils/daggerverse/tree/28eea1fcf3b6ecb38a628186107760acd717442f/k3s/main.go#L51)
	q := r.query.Select("k3S")
	for i := len(opts) - 1; i >= 0; i-- {
		// `image` optional argument
		if !querybuilder.IsZeroValue(opts[i].Image) {
			q = q.Arg("image", opts[i].Image)
		}
		// `keepState` optional argument
		if !querybuilder.IsZeroValue(opts[i].KeepState) {
			q = q.Arg("keepState", opts[i].KeepState)
		}
	}
	q = q.Arg("name", name)

	return &K3S{
		query: q,
	}
}
