// Code generated by Azure.Iot.Operations.ProtocolCompilerLib v0.10.0.0; DO NOT EDIT.
package schemaregistry

import (
	"encoding/json"
	"errors"
)

/// Supported schema formats
type Format int32

const (
	FormatDelta1 Format = iota
	FormatJsonSchemaDraft07 Format = iota
)

func (v Format) String() string {
	switch v {
	case FormatDelta1:
		return "Delta1"
	case FormatJsonSchemaDraft07:
		return "JsonSchemaDraft07"
	default:
		return ""
	}
}

func (v Format) MarshalJSON() ([]byte, error) {
	var s string
	switch v {
	case FormatDelta1:
		s = "Delta/1.0"
	case FormatJsonSchemaDraft07:
		s = "JsonSchema/draft-07"
	default:
		return []byte{}, errors.New("unable to marshal unrecognized enum value to JSON")
	}

	return json.Marshal(s)
}

func (v *Format) UnmarshalJSON(b []byte) error {
	var s string
	if err := json.Unmarshal(b, &s); err != nil {
		return err
	}

	switch s {
	case "Delta/1.0":
		*v = FormatDelta1
	case "JsonSchema/draft-07":
		*v = FormatJsonSchemaDraft07
	default:
		return errors.New("unable to unmarshal unrecognized enum value from JSON")
	}

	return nil
}
