package shell

import (
	"fmt"

	"notabug.org/Umnik/GoAndroidSDK/v2/components/sdk/platformTools/adb/connection"
)

type DeviceShell struct {
	connection connection.Connection
}

func (d DeviceShell) Connection() connection.Connection {
	return d.connection
}

// Ls executes "ls" command with args (if passed) on device
func (d DeviceShell) Ls(lsPath string, args ...string) ([]byte, error) {
	fc := append(args, lsPath)
	return d.RunSync("ls", fc...)
}

// MkDir executes "mkdir" with args (if passed) on device
func (d DeviceShell) MkDir(dirPath string, args ...string) ([]byte, error) {
	fc := append([]string{dirPath}, args...)
	return d.RunSync("mkdir", fc...)
}

// Rm executes "rm" with args (if passed) on device
func (d DeviceShell) Rm(object string, args ...string) ([]byte, error) {
	fc := append([]string{object}, args...)
	return d.RunSync("rm", fc...)
}

func (d DeviceShell) OrchestratorClassMethod(classMethod string, runner string) ([]byte, error) {
	return d.RunSync(fmt.Sprintf("CLASSPATH=$(pm path androidx.test.services) app_process / "+
		"androidx.test.services.shellexecutor.ShellMain am instrument -w -e class %s %s/androidx.test.runner.AndroidJUnitRunner "+
		"androidx.test.orchestrator/.AndroidTestOrchestrator", classMethod, runner))
}
