// Code generated by "enumer -type=Semver"; DO NOT EDIT
/*

SPDX-Copyright: Copyright (c) Capital One Services, LLC
SPDX-License-Identifier: Apache-2.0
Copyright 2017 Capital One Services, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.

*/
package model

import (
	"encoding/json"
	"fmt"
)

// Semver is an enum.
// It is serialized as a string in JSON and as an integer in SQL.

// Semver enum maps.
var (
	strMapSemver = map[string]Semver{
		"major": Major,
		"minor": Minor,
		"patch": Patch,
		"none":  None,
	}

	intMapSemver = map[Semver]string{
		Major: "major",
		Minor: "minor",
		Patch: "patch",
		None:  "none",
	}
)

// Known says whether or not this value is a known enum value.
func (s Semver) Known() bool {
	_, ok := intMapSemver[s]
	return ok
}

// String is for the standard stringer interface.
func (s Semver) String() string {
	return intMapSemver[s]
}

// UnmarshalJSON satisfies the json.Unmarshaler
func (s *Semver) UnmarshalJSON(data []byte) error {
	str := ""
	err := json.Unmarshal(data, &str)
	if err != nil {
		return err
	}
	var ok bool
	*s, ok = strMapSemver[str]
	if !ok {
		return fmt.Errorf("Unknown Semver enum value: %s", str)
	}
	return nil
}

// MarshalJSON satisfies the json.Marshaler
func (s Semver) MarshalJSON() ([]byte, error) {
	if !s.Known() {
		return nil, fmt.Errorf("Unknown Semver enum value: %d", int(s))
	}
	name := intMapSemver[s]
	return json.Marshal(name)
}
