package baseadapter

import (
	"fmt"
	"io"
	"net/http"
	"net/url"
)

type Rest struct {
	baseURL     string
	bearerToken string
}

func (b *Rest) createRequest(method string, body io.Reader, path ...string) (r *http.Request, err error) {
	target, err := url.JoinPath(b.baseURL, path...)
	if err != nil {
		err = fmt.Errorf("can not parse path: %w", err)
		return
	}
	req, err := http.NewRequest(method, target, body)
	if err != nil {
		return nil, err
	}

	if b.bearerToken != "" {
		req.Header.Set("Authorization", "Bearer "+b.bearerToken)
	}

	return req, nil
}
