package libamuse

import (
	"notabug.org/apiote/amuse/front"

	"notabug.org/apiote/gott"

	"golang.org/x/text/language"
)

type data interface {
	getLanguage() string
	getMimeType() string
}

func parseLanguage(args ...interface{}) (interface{}, error) {
	data := args[0].(data)
	tags, _, err := language.ParseAcceptLanguage(data.getLanguage())
	if tags == nil {
		tags = []language.Tag{}
	}
	if len(tags) == 0 {
		tags = append(tags, language.Make("en-GB"))
	}
	args[2] = tags
	return gott.Tuple(args), err
}

func createRenderer(args ...interface{}) (interface{}, error) {
	data := args[0].(data)
	renderer, err := front.NewRenderer(data.getMimeType())
	args[3] = renderer
	return gott.Tuple(args), err
}

type requestData struct {
	id       string
	etag     string
	language string
	mimetype string
}

func (d requestData) getLanguage() string {
	return d.language
}

func (d requestData) getMimeType() string {
	return d.mimetype
}
