package apikeys

import (
	"context"

	"update_server/internal/db"
)

type contextKey string

const requestContextKey contextKey = "api-key"

type AuthState struct {
	APIKey db.APIKey
}

func NewContext(ctx context.Context, state *AuthState) context.Context {
	if state == nil {
		return ctx
	}

	return context.WithValue(ctx, requestContextKey, *state)
}

func FromContext(ctx context.Context) (*AuthState, bool) {
	state, ok := ctx.Value(requestContextKey).(AuthState)
	if !ok {
		return nil, false
	}

	return &state, true
}
