package main

import (
	"fmt"
	"os/exec"
	"strings"

	tea "github.com/charmbracelet/bubbletea"
)

func saveAndValidateCmd(path string, p *Profile) tea.Cmd {
	return func() tea.Msg {
		if err := SaveProfile(path, p); err != nil {
			return saveResultMsg{err: err}
		}
		cmd := exec.Command("nono", "profile", "validate", "opencode-tinfoil")
		out, err := cmd.CombinedOutput()
		output := strings.TrimSpace(string(out))
		if err != nil {
			return saveResultMsg{output: output, err: fmt.Errorf("validation failed")}
		}
		return saveResultMsg{output: output}
	}
}

func main() {
	m, _ := NewModel()
	p := tea.NewProgram(m, tea.WithAltScreen())
	if _, err := p.Run(); err != nil {
		fmt.Printf("Error: %v\n", err)
	}
}
