package auth_connectors

import (
	"net/http"
	"oc-auth/conf"

	"cloud.o-forge.io/core/oc-lib/tools"
)

type AuthConnector interface {
	Status() tools.State
	Login(clientID string, username string, cookies ...*http.Cookie) (*Token, error)
	Logout(clientID string, token string, cookies ...*http.Cookie) (*Token, error)
	Introspect(token string, cookie ...*http.Cookie) (bool, error)
	Refresh(client_id string, token *Token) (*Token, error)
	CheckAuthForward(reqToken string, publicKey string, host string, method string, forward string, external bool) bool
}

type Token struct {
	Active      bool   `json:"active"`
	AccessToken string `json:"access_token"`
	ExpiresIn   int64  `json:"expires_in"`
	TokenType   string `json:"token_type"`

	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

type Redirect struct {
	RedirectTo string `json:"redirect_to"`
}

var a = map[string]AuthConnector{
	"hydra": HydraConnector{
		Caller: tools.NewHTTPCaller(map[tools.DataType]map[tools.METHOD]string{}),
		State:  "12345678", ResponseType: "token", Scopes: "openid profile email roles"}, // base url
}

func GetAuthConnector() AuthConnector {
	return a[conf.GetConfig().Auth]
}
