package zipalign

import "notabug.org/Umnik/GoAndroidSDK/v2/components/executor"

// Zipalign represents zipalign util
type Zipalign struct {
	binPath string
}

func (z Zipalign) BinPath() string {
	return z.binPath
}

// DoAlign executes align for apk file
func (z Zipalign) DoAlign(in, out, align string, overwrite, alignSharedObjects, verbose bool) ([]byte, error) {
	var args []string

	if overwrite {
		args = append(args, "-f")
	}
	if alignSharedObjects {
		args = append(args, "-p")
	}
	if verbose {
		args = append(args, "-v")
	}
	args = append(args, align, in, out)

	return executor.RunSync(z, args[0], args[1:]...)
}

// CheckAlign checks align for apk file
func (z Zipalign) CheckAlign(in, align string, alignSharedObjects, verbose bool) ([]byte, error) {
	var args []string

	if alignSharedObjects {
		args = append(args, "-p")
	}
	if verbose {
		args = append(args, "-v")
	}
	args = append(args, align, in)
	return executor.RunSync(z, "-c", args...)
}
