package fetch

import "net/http"

type (
	Options struct {
		Url    string
		Method string
		Header map[string]string
		Params map[string]string
		Data   any
		Human  bool
	}
	Option func(o *Options)
)

func WithUrl(s string) Option {
	return func(o *Options) {
		o.Url = s
	}
}

func WithMethod(s string) Option {
	return func(o *Options) {
		o.Method = s
	}
}

func WithHeader(h map[string]string) Option {
	return func(o *Options) {
		if o.Header == nil {
			o.Header = h
		}
		for k, v := range o.Header {
			o.Header[k] = v
		}
	}
}

func WithHuman() Option {
	return func(o *Options) {
		o.Human = true
	}
}

func WithParams(h map[string]string) Option {
	return func(o *Options) {
		o.Params = h
	}
}

func WithData(v any) Option {
	return func(o *Options) {
		o.Data = v
	}
}

func newOptions() *Options {
	return &Options{
		Method: http.MethodGet,
	}
}