package main

import (
	"fmt"
	"net/http"
)
import "github.com/gorilla/schema"

var decoder = schema.NewDecoder()

func setupSite(mux *http.ServeMux) {
	form{
		path: "/kontakt",
		toSubmission: func(r *http.Request) (submission, error) {
			var data struct {
				Name    string `schema:"contactname"`
				Email   string `schema:"contactemail"`
				Message string `schema:"message"`
			}

			err := decoder.Decode(&data, r.PostForm)
			if err != nil {
				return submission{}, fmt.Errorf("POST decode error: %w", err)
			}

			return submission{
				group:       "",
				category:    "",
				message:     "",
				information: nil,
			}, nil
		},
	}.setup(mux)

	form{
		path: "/computer-beantragen/privat",
		toSubmission: func(r *http.Request) (submission, error) {
			var data struct {
				Name        string `schema:"contactname"`
				Email       string `schema:"contactemail"`
				Message     string `schema:"message"`
				Addressline string `schema:"addressline"`
				Postalcode  string `schema:"postalcode"`
				City        string `schema:"city"`
			}

			err := decoder.Decode(&data, r.PostForm)
			if err != nil {
				return submission{}, fmt.Errorf("POST decode error: %w", err)
			}

			//documentFile, documentHeader, err := r.FormFile("document")
			//if err != nil {
			//	return submission{}, fmt.Errorf("could not extract document upload: %w", err)
			//}
			//documentType := mime.TypeByExtension(documentHeader.Filename)

			return submission{
				group:       "",
				category:    "",
				message:     "",
				information: nil,
			}, nil
		},
	}.setup(mux)
}
