package app

import (
	"bytes"
	"fmt"
	"log"
	"os/exec"
)

func pressDiscordMuteHotkey() error {
	script := `
$p = Get-Process | Where-Object { $_.MainWindowTitle -match 'Discord' } | Select-Object -First 1
if ($null -eq $p) { exit 2 }
[void][System.Runtime.InteropServices.Marshal]::GetLastWin32Error()
$wshell = New-Object -ComObject WScript.Shell
$null = $wshell.AppActivate($p.Id)
Start-Sleep -Milliseconds 150
$wshell.SendKeys('^+m')
`

	cmd := exec.Command("powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", script)
	out, err := cmd.CombinedOutput()
	if len(out) > 0 {
		log.Printf("discord mute output: %s", string(out))
	}
	if err != nil {
		return fmt.Errorf("discord mute failed: %w", err)
	}
	return nil
}

func pressDiscordMuteHotkeyLegacy() error {
	var buf bytes.Buffer
	_ = buf
	return pressDiscordMuteHotkey()
}
