// Copyright 2013 The Prometheus Authors
// 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 (
	
	
	
	
	
)

// ZeroSamplePair is the pseudo zero-value of SamplePair used to signal a
// non-existing sample pair. It is a SamplePair with timestamp Earliest and
// value 0.0. Note that the natural zero value of SamplePair has a timestamp
// of 0, which is possible to appear in a real SamplePair and thus not
// suitable to signal a non-existing SamplePair.
var ZeroSamplePair = SamplePair{Timestamp: Earliest}

// A SampleValue is a representation of a value for a given sample at a given
// time.
type SampleValue float64

// MarshalJSON implements json.Marshaler.
func ( SampleValue) () ([]byte, error) {
	return json.Marshal(.String())
}

// UnmarshalJSON implements json.Unmarshaler.
func ( *SampleValue) ( []byte) error {
	if len() < 2 || [0] != '"' || [len()-1] != '"' {
		return errors.New("sample value must be a quoted string")
	}
	,  := strconv.ParseFloat(string([1:len()-1]), 64)
	if  != nil {
		return 
	}
	* = SampleValue()
	return nil
}

// Equal returns true if the value of v and o is equal or if both are NaN. Note
// that v==o is false if both are NaN. If you want the conventional float
// behavior, use == to compare two SampleValues.
func ( SampleValue) ( SampleValue) bool {
	if  ==  {
		return true
	}
	return math.IsNaN(float64()) && math.IsNaN(float64())
}

func ( SampleValue) () string {
	return strconv.FormatFloat(float64(), 'f', -1, 64)
}

// SamplePair pairs a SampleValue with a Timestamp.
type SamplePair struct {
	Timestamp Time
	Value     SampleValue
}

func ( SamplePair) () ([]byte, error) {
	,  := json.Marshal(.Timestamp)
	if  != nil {
		return nil, 
	}
	,  := json.Marshal(.Value)
	if  != nil {
		return nil, 
	}
	return []byte(fmt.Sprintf("[%s,%s]", , )), nil
}

// UnmarshalJSON implements json.Unmarshaler.
func ( *SamplePair) ( []byte) error {
	 := [...]json.Unmarshaler{&.Timestamp, &.Value}
	return json.Unmarshal(, &)
}

// Equal returns true if this SamplePair and o have equal Values and equal
// Timestamps. The semantics of Value equality is defined by SampleValue.Equal.
func ( *SamplePair) ( *SamplePair) bool {
	return  ==  || (.Value.Equal(.Value) && .Timestamp.Equal(.Timestamp))
}

func ( SamplePair) () string {
	return fmt.Sprintf("%s @[%s]", .Value, .Timestamp)
}