package command

import (
	"github.com/pingcap/tiflow/cdc/model"
	"go.uber.org/zap"
)

type CdcCmd struct{ ExecCmd }

type CdcRedoCmd struct{ ExecCmd }

type CdcCliCmd struct{ ExecCmd }

type CdcCliChangeFeedCmd struct{ ExecCmd }

func (c *CdcCmd) Redo() *CdcRedoCmd {
	return &CdcRedoCmd{ExecCmd{Command: "redo", Options: nil, ParentCmd: c}}
}

func (c *CdcRedoCmd) Apply(args []string) *CdcRedoCmd {
	return &CdcRedoCmd{ExecCmd{Command: "apply", Options: args, ParentCmd: c}}
}

func (c *CdcRedoCmd) Meta(args []string) *CdcRedoCmd {
	return &CdcRedoCmd{ExecCmd{Command: "meta", Options: args, ParentCmd: c}}
}

func (c *CdcCmd) Cli() *CdcCliCmd {
	return &CdcCliCmd{ExecCmd{Command: "cli", Options: nil, ParentCmd: c}}
}

func (c *CdcCliCmd) ChangeFeed() *CdcCliChangeFeedCmd {
	return &CdcCliChangeFeedCmd{ExecCmd{Command: "changefeed", Options: nil, ParentCmd: c}}
}

func (c *CdcCliChangeFeedCmd) Create(args []string) *CdcCliChangeFeedCmd {
	return &CdcCliChangeFeedCmd{ExecCmd{Command: "create", Options: args, ParentCmd: c}}
}

func (c *CdcCliChangeFeedCmd) Update(args []string) *CdcCliChangeFeedCmd {
	return &CdcCliChangeFeedCmd{ExecCmd{Command: "update", Options: args, ParentCmd: c}}
}

func (c *CdcCliChangeFeedCmd) Query(args []string) *CdcCliChangeFeedCmd {
	return &CdcCliChangeFeedCmd{ExecCmd{Command: "query", Options: args, ParentCmd: c}}
}

func (c *CdcCliChangeFeedCmd) List(args []string) *CdcCliChangeFeedCmd {
	return &CdcCliChangeFeedCmd{ExecCmd{Command: "list", Options: args, ParentCmd: c}}
}

func (c *CdcCliChangeFeedCmd) Admin(jobType model.AdminJobType, params []string) *CdcCliChangeFeedCmd {
	var cmd string
	switch jobType {
	case model.AdminStop:
		cmd = "pause"
	case model.AdminResume:
		cmd = "resume"
	case model.AdminRemove:
		cmd = "remove"
	default:
		logger.Panic("invalid admin job", zap.String("jobType", jobType.String()))
	}

	return &CdcCliChangeFeedCmd{ExecCmd{Command: cmd, Options: params, ParentCmd: c}}
}
