package main

import (
	"flag"
	"log"
	"os"
	"path/filepath"

	"vrc_osc_go/internal/buildinfo"
	"vrc_osc_go/internal/common"
	"vrc_osc_go/internal/update"
)

func main() {
	var baseURL string
	var ownerRepo string
	var assetName string
	flag.StringVar(&baseURL, "base-url", "https://git.vrcworldtour.com", "Gitea base URL")
	flag.StringVar(&ownerRepo, "repo", "every_holiday/VRCWT-OSC", "owner/repo")
	flag.StringVar(&assetName, "asset", "vrc_osc-windows.zip", "release asset name")
	flag.Parse()

	client := &update.Client{BaseURL: baseURL}
	mgr := &update.Manager{
		Client:       client,
		OwnerRepo:    ownerRepo,
		AssetName:    assetName,
		CurrentLabel: buildinfo.Version,
	}
	if _, err := mgr.CheckAndUpdate(); err != nil {
		log.Printf("auto update skipped: %v", err)
	}
	exe := filepath.Join(common.RootDir(), "vrc_osc.exe")
	if _, err := os.Stat(exe); err != nil {
		log.Fatalf("missing exe: %v", err)
	}
	if err := update.Launch(exe, os.Args[1:]); err != nil {
		log.Fatalf("launch failed: %v", err)
	}
}
