package main

import (
	"fmt"

	"github.com/urfave/cli/v2"
	"golang.org/x/xerrors"

	lcli "github.com/filecoin-project/lotus/cli"
)

var setCmd = &cli.Command{
	Name:   "set",
	Usage:  "Manage worker settings",
	Hidden: true,
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:  "enabled",
			Usage: "enable/disable new task processing",
			Value: true,
		},
	},
	Action: func(cctx *cli.Context) error {
		fmt.Println("DEPRECATED: This command will be removed in the future")
		api, closer, err := lcli.GetWorkerAPI(cctx)
		if err != nil {
			return err
		}
		defer closer()

		ctx := lcli.ReqContext(cctx)

		if err := api.SetEnabled(ctx, cctx.Bool("enabled")); err != nil {
			return xerrors.Errorf("SetEnabled: %w", err)
		}

		return nil
	},
}

var waitQuietCmd = &cli.Command{
	Name:   "wait-quiet",
	Usage:  "Block until all running tasks exit",
	Hidden: true,
	Action: func(cctx *cli.Context) error {
		fmt.Println("DEPRECATED: This command will be removed in the future")
		api, closer, err := lcli.GetWorkerAPI(cctx)
		if err != nil {
			return err
		}
		defer closer()

		ctx := lcli.ReqContext(cctx)

		return api.WaitQuiet(ctx)
	},
}
