package pm

import (
	"strings"

	"notabug.org/Umnik/GoAndroidSDK/v2/components/misc"
)

func trimPackageWord(raw []byte) []string {
	str := string(raw)
	key := "package:"
	result := make([]string, strings.Count(str, key))

	for i, line := range strings.Split(str, "\n") {
		if strings.HasPrefix(line, key) {
			result[i] = misc.TwoSpotValue(strings.TrimSpace(line))
		}
	}
	return result
}

// ParseInstalledApps returns installed packages as []string
func ParseInstalledApps(rawOutput []byte) []string {
	return trimPackageWord(rawOutput)
}

// ParsePackagePath returns package path as []string
func ParsePackagePath(rawOutput []byte) []string {
	return trimPackageWord(rawOutput)
}
