package main

import (
	"encoding/json"
	"fmt"
	"log"
	"math/rand"
	"net/http"
)

func homePage(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Welcome to the Agresija!")
	fmt.Println("Endpoint Hit: homePage")
}

func handleRequests() {
	http.HandleFunc("/api/answer", answerHandler)
	http.HandleFunc("/", randomQuestionHandler)
	log.Fatal(http.ListenAndServe(":10000", nil))
}

func main() {
	initializeQuestions()
	handleRequests()
}

func answerHandler(w http.ResponseWriter, r *http.Request) {
	randomIndex := rand.Intn(len(Questions))
	question := Questions[randomIndex]
	json.NewEncoder(w).Encode(question)
}
