package safe

import (
	"errors"
	"html/template"
	"reflect"
)

type Namespace struct{}

var ErrSafeHTML error = errors.New("unsupported input type for SafeHTML")

func New() *Namespace {
	return &Namespace{}
}

func (Namespace) HTML(v reflect.Value) (template.HTML, error) {
	switch v.Kind() {
	default:
		return "", ErrSafeHTML
	case reflect.Slice:
		switch v.Type().Elem().Kind() {
		default:
			return "", ErrSafeHTML
		case reflect.Uint8:
			return template.HTML(v.Bytes()), nil
		}
	case reflect.String:
		return template.HTML(v.String()), nil
	}
}
