package http

import (
	"net/http"
	"os"
)

type HttpParameter struct {
	jsonParamer string
	params      map[string]interface{}
	files       map[string]*os.File
	listFiles   map[string][]*os.File
	httpMethod  string
}

func NewGetHttpParameter() *HttpParameter {
	param := HttpParameter{
		params:     make(map[string]interface{}),
		files:      make(map[string]*os.File),
		listFiles:  make(map[string][]*os.File),
		httpMethod: http.MethodGet,
	}
	return &param
}

func NewPostHttpParameter() *HttpParameter {
	param := HttpParameter{
		params:     make(map[string]interface{}),
		files:      make(map[string]*os.File),
		listFiles:  make(map[string][]*os.File),
		httpMethod: http.MethodPost,
	}
	return &param
}

func (h *HttpParameter) JsonParamer() string {
	return h.jsonParamer
}

func (h *HttpParameter) SetJsonParamer(jsonParamer string) {
	h.jsonParamer = jsonParamer
}

func (h *HttpParameter) Params() map[string]interface{} {
	return h.params
}

func (h *HttpParameter) AddParam(key string, value interface{}) {
	h.params[key] = value
}

func (h *HttpParameter) SetParams(params map[string]interface{}) {
	h.params = params
}

func (h *HttpParameter) Files() map[string]*os.File {
	return h.files
}

func (h *HttpParameter) AddFiles(key string, file *os.File) {
	h.files[key] = file
}

func (h *HttpParameter) SetFiles(files map[string]*os.File) {
	h.files = files
}

func (h *HttpParameter) ListFiles() map[string][]*os.File {
	return h.listFiles
}

func (h *HttpParameter) AddListFiles(key string, listFiles []*os.File) {
	h.listFiles[key] = listFiles
}

func (h *HttpParameter) SetListFiles(listFiles map[string][]*os.File) {
	h.listFiles = listFiles
}

func (h *HttpParameter) HttpMethod() string {
	return h.httpMethod
}

func (h *HttpParameter) IsJson() bool {
	if len(h.jsonParamer) == 0 {
		return false
	}
	return true
}

func (h *HttpParameter) IsMultipart() bool {
	if len(h.files) == 0 && len(h.listFiles) == 0 {
		return false
	}
	return true
}
