package main

import (
	"flag"
	"log"
	"net/http"

	"git.tovijaeschke.xyz/tovi/Capsule/Backend/Api"
	"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database"
	"git.tovijaeschke.xyz/tovi/Capsule/Backend/Database/Seeder"

	"github.com/gorilla/mux"
)

var seed bool

func init() {
	Database.Init()

	flag.BoolVar(&seed, "seed", false, "Seed database for development")

	flag.Parse()
}

func main() {
	var (
		router *mux.Router
		err    error
	)

	if seed {
		Seeder.Seed()
		return
	}

	router = mux.NewRouter()

	Api.InitAPIEndpoints(router)

	log.Println("Listening on port :8080")
	err = http.ListenAndServe(":8080", router)
	if err != nil {
		panic(err)
	}
}
