#!/bin/bash

start() {
	if [ "$1" = "normal" ]; then
		sudo ryzenadj-service --stapm-limit 30000 --fast-limit 30000 --slow-limit 30000 --slow-time 60 --stapm-time 1000 --tctl-temp 85 --vrmmax-current 50000 &>/dev/null &
		echo $! >/tmp/ryzenadj-service.pid
		disown "$(cat /tmp/ryzenadj-service.pid)"
		echo "normal" >/tmp/ryzenadj-service.profile
	elif [ "$1" = "performance" ]; then
		sudo ryzenadj-service --stapm-limit 35000 --fast-limit 35000 --slow-limit 35000 --slow-time 60 --stapm-time 1000 --tctl-temp 85 --vrmmax-current 65000 &>/dev/null &
		echo $! >/tmp/ryzenadj-service.pid
		disown "$(cat /tmp/ryzenadj-service.pid)"
		echo "performance" >/tmp/ryzenadj-service.profile
	elif [ "$1" = "max-performance" ]; then
		sudo ryzenadj-service --stapm-limit 35000 --fast-limit 35000 --slow-limit 35000 --slow-time 60 --stapm-time 1000 --tctl-temp 85 --vrmmax-current 70000 &>/dev/null &
		echo $! >/tmp/ryzenadj-service.pid
		disown "$(cat /tmp/ryzenadj-service.pid)"
		echo "max-performance" >/tmp/ryzenadj-service.profile
	fi
}

main() {
	if [ "$1" = "normal" ]; then
		[ -f "/tmp/ryzenadj-service.pid" ] && kill $(cat /tmp/ryzenadj-service.pid)
		start "normal"
	elif [ "$1" = "performance" ]; then
		[ -f "/tmp/ryzenadj-service.pid" ] && kill $(cat /tmp/ryzenadj-service.pid)
		start "performance"
	elif [ "$1" = "max-performance" ]; then
		[ -f "/tmp/ryzenadj-service.pid" ] && kill $(cat /tmp/ryzenadj-service.pid)
		start "max-performance"
	fi
}

main $@