package shell

import (
	"fmt"
	"os/exec"
)

// StartVideo creates video in mp4 format and saves it in fileName. It is allowed to set h, w and Mpb less than zero for use device's defaults.
// 1440x3120 means w = 1440, h = 3120
func (d DeviceShell) StartVideo(w, h, Mbps int, bugreport bool, fileName string) (*exec.Cmd, error) {
	var cmdLine []string

	if w < 0 || h < 0 {
		if w >= 0 || h >= 0 {
			panic("h and w both must be less than zero in same time!")
		}
	} else {
		cmdLine = append(cmdLine, "--size", fmt.Sprintf("%dx%d", w, h))
	}

	if Mbps >= 0 {
		cmdLine = append(cmdLine, "--bit-rate", fmt.Sprintf("%dM", Mbps))
	}

	if bugreport {
		cmdLine = append(cmdLine, "--bugreport")
	}

	cmdLine = append(cmdLine, fileName)

	return d.StartAsync("screenrecord", cmdLine...)
}

// StopVideo stops screen records
func (d DeviceShell) StopVideo(process *exec.Cmd) error {
	return d.StopAsync(process)
}
