package main

import (
	"fmt"
	"os"
	"strconv"
)

// TODO:
// - Flags instead of os.Args
// - Interactive UI
// - Check compatability with other image types (PNG etc)
// - better ffmpeg bindings (go package?)

const MAX_SIZE = 1000000

func main() {
	if len(os.Args) < 5 {
		fmt.Println("Usage: go run main.go <source-file> <number-of-copies> <shit-size> <iterations>")
		return
	}

	sourceFile := os.Args[1]
	numCopies, err := strconv.Atoi(os.Args[2])
	if err != nil || numCopies <= 0 {
		fmt.Println("Invalid number of copies. Must be a positive integer.")
		return
	}

	shitSize, err := strconv.ParseInt(os.Args[3], 10, 64) // Parse shitSize as int64
	if err != nil || shitSize <= 0 {
		fmt.Println("Invalid shit size. Must be a positive integer.")
		return
	} else if shitSize > MAX_SIZE {
		fmt.Printf("shitSize exceeds maximum size (%d)\n", MAX_SIZE)
		return
	}

	iterations, err := strconv.ParseInt(os.Args[4], 10, 8)
	check(err, "Cannot parse iterations. Must be a positive integer")

	makeOutputDir()
	generateGlitchedSequence(sourceFile, numCopies, shitSize, iterations)
	ffmpegGenerateMP4()
	clearOutputDir()
}
