package srv

import (
	"fmt"
	"net/http"
	"time"
)

type Res struct {
	w http.ResponseWriter
	r *http.Request
}

func (res *Res) Construct(w http.ResponseWriter, r *http.Request) {
	res.w = w
	res.r = r
}

func (res *Res) Send(txt string) {
	fmt.Fprint(res.w, txt)
}

func (res *Res) Redirect(url string) {
	http.Redirect(res.w, res.r, url, http.StatusTemporaryRedirect)
}

func (res *Res) Cookie(name string, val string) {
	cookie := &http.Cookie{
		Name:     name,
		Value:    val,
		Expires:  time.Now().Add(365 * 24 * time.Hour),
		Path:     "/",
		Secure:   true,
		HttpOnly: true,
		SameSite: http.SameSiteStrictMode,
	}

	http.SetCookie(res.w, cookie)
}
