package ordoor

import (
	"log"
	"os/exec"
)

func (o *Ordoor) PlayVideo(name string, skippable bool) {
	filename := o.config.DataFile("SMK/" + name + ".smk")

	if len(o.config.VideoPlayer) == 0 {
		log.Printf("Video player not configured, skipping video %v", filename)
		return
	}

	argc := o.config.VideoPlayer[0]
	argv := append(o.config.VideoPlayer[1:])
	if skippable {
		argv = append(argv, "--input-conf=skippable.mpv.conf")
	}

	argv = append(argv, filename)

	if err := exec.Command(argc, argv...).Run(); err != nil {
		log.Printf("Error playing video %v: %v", filename, err)
	}
}

func (o *Ordoor) PlayUnskippableVideo(name string) {
	o.PlayVideo(name, false)
}

func (o *Ordoor) PlaySkippableVideo(name string) {
	o.PlayVideo(name, true)
}
