// Package oapi provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/deepmap/oapi-codegen version v1.12.4 DO NOT EDIT.
package oapi

import (
	"bytes"
	"compress/gzip"
	"encoding/base64"
	"fmt"
	"net/url"
	"path"
	"strings"

	"github.com/getkin/kin-openapi/openapi3"
)

// Base64 encoded, gzipped, json marshaled Swagger object
var swaggerSpec = []string{

	"H4sIAAAAAAAC/7RWf2/bOBL9KgPmgLsCjuRr74BC/6Vp0ATrboMk3XZRF81IGstMKA5Ljuxqi3z3BSn/",
	"SuJ2Ayz2P1scPr55M3zD76ri1rElK0EV31Wo5tRi+nm0DBNuLkjIimZ7Zl0n8bvz7MiLphSFVUUh/EL9",
	"2ev4V3pHqlBBvLaNuhspT41m+4OlDfRr7BNaTTPsjKjivy/HIzVj36KoQmkrL56r0RpCW6GGfMQIVHmS",
	"ozWJvecECkGzveJb2kckMfnaaU+1Kj7dS+gx/gO0TX6fN+S4vKFK4rkPBHzXyV4FWwoBm+G3FmrTj395",
	"mqlCHeTb8uSr2uRvhw3xiNWZ6D32jzLZAO8jtwZ5XFC/v1rtdsOjNUvL39B0afEJRXOeFpq78PQ9+zNT",
	"o8T2IeAOn8eZRyhtZzx0W6i8dpIaVB3AuwX5habl1E5tZbirD5foa7L/DnDDJegAC/I9BN06QxmcSfwk",
	"DJUhtIC2BnaiW/0HQdoOngJ3vqKQTe3VXIcY7zgEXRqCsoeWaz3rtW1ggT4msNoXIo+KAlRsZ7rpPEaO",
	"8SiElj0N56CBioNMbeiqOWCAOjYrhoi3uVvgUSiM1syGta8dBaEa5ujrJXoaAVksTVxk+6WmNubSRYmz",
	"qMVx5z1ZMf0I2Joejj5cwnEk+gGlmsOEG3jjuXPwbjhkYKsDhM459kJ1gjmA07M3p5Pf4eTj+cnF2duT",
	"X6+OJpDD0eT89AguBRuKYYOsnipuW7I11SBzFJA5pYMv2BA0ekFJD4mqBp5JTCPKJagttNomeRz5Vqfr",
	"ui6Aw+oWGxrIpZaIKKUnvI3ZV3O0DQVAAbS96PaBAIlF0mALHaALVAN6Kqb2EAw3oTjvZHPvz9noqt8s",
	"vU5NV9KEmyRaSNIcwCkvI5X3IYmQyHpyHLSw7yNfBIQSq1uyQ4OQT9wmsb4Cl0tsGvJw6ahK0QvUBmOf",
	"ocCnuYgLRZ43WuZdmVXc5jfYH5ZYdvlup+el4TJvUduc0elcuOasb83n//xdhGerNC/XLQGXqyaPyuzr",
	"pjC1AIew0RHWQiacYzSpXy9i8ie2dqytxLWLobsDVGihJGixpigsaZmTB57FGgYCWu0JScXDrUa72Ryi",
	"05lDIXODfaZ5q8PPop79EC9j62NP+yjgfrB7IWvVLjprY7YTrtCYfsjTMUy0vS2eXt6nl/HZIMq554Wu",
	"CXaG4ggezMQRDDMwLmxHY/Qjh15Wgq9NB0qu+yxCX2f3DrwGPYOal9YwxjvvyRAGgpk2lMJbvCXw3RDo",
	"V3rMPLcweOw2aBn76BrEY3UbYMY+gWzudpcM8hq1v57G4SFaTJwQR50wXHU2DpAF+TBMhXE2zsZxaLEj",
	"i06rQr1In0bKoczTyMxxGXLDzZcm9m2+8d40XDnI41nzNhq/prDjnds+13bnPmRTe7wivvV0l27C/cCd",
	"i5MsjcAyNJ5QyEcHtXD94MF1HQuELUlykp3tSy1zQAgtGkMe6JvTqwlUo1B0OrAsw/TSydxV0mcIOqtV",
	"odbutslKDROcgrziOr3TolmTTeKgc0ZXaXd+EwbhhtfOX72F9j5S05DfI3i/I/c97YbXaHBsw/AIej4e",
	"/1MUV8/APRz39cIlLqjOIr//DZTub3mFNawMLwX9/+PHx0HvLX1zVEXPJe/ZZ/Hwu/QwjlMkqOLTd9V5",
	"owr1FHdTd6Ofhd/zrwexRZ6b6GBzDlK8HL8cq7vPd38GAAD//wG7aKWDDAAA",
}

// GetSwagger returns the content of the embedded swagger specification file
// or error if failed to decode
func decodeSpec() ([]byte, error) {
	zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
	if err != nil {
		return nil, fmt.Errorf("error base64 decoding spec: %s", err)
	}
	zr, err := gzip.NewReader(bytes.NewReader(zipped))
	if err != nil {
		return nil, fmt.Errorf("error decompressing spec: %s", err)
	}
	var buf bytes.Buffer
	_, err = buf.ReadFrom(zr)
	if err != nil {
		return nil, fmt.Errorf("error decompressing spec: %s", err)
	}

	return buf.Bytes(), nil
}

var rawSpec = decodeSpecCached()

// a naive cached of a decoded swagger spec
func decodeSpecCached() func() ([]byte, error) {
	data, err := decodeSpec()
	return func() ([]byte, error) {
		return data, err
	}
}

// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
	var res = make(map[string]func() ([]byte, error))
	if len(pathToFile) > 0 {
		res[pathToFile] = rawSpec
	}

	return res
}

// GetSwagger returns the Swagger specification corresponding to the generated code
// in this file. The external references of Swagger specification are resolved.
// The logic of resolving external references is tightly connected to "import-mapping" feature.
// Externally referenced files must be embedded in the corresponding golang packages.
// Urls can be supported but this task was out of the scope.
func GetSwagger() (swagger *openapi3.T, err error) {
	var resolvePath = PathToRawSpec("")

	loader := openapi3.NewLoader()
	loader.IsExternalRefsAllowed = true
	loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
		var pathToFile = url.String()
		pathToFile = path.Clean(pathToFile)
		getSpec, ok := resolvePath[pathToFile]
		if !ok {
			err1 := fmt.Errorf("path not found: %s", pathToFile)
			return nil, err1
		}
		return getSpec()
	}
	var specData []byte
	specData, err = rawSpec()
	if err != nil {
		return
	}
	swagger, err = loader.LoadFromData(specData)
	if err != nil {
		return
	}
	return
}
