package colorful

import (
	
	
	
	
)

// A HexColor is a Color stored as a hex string "#rrggbb". It implements the
// database/sql.Scanner, database/sql/driver.Value,
// encoding/json.Unmarshaler and encoding/json.Marshaler interfaces.
type HexColor Color

type errUnsupportedType struct {
	got  interface{}
	want reflect.Type
}

func ( *HexColor) ( interface{}) error {
	,  := .(string)
	if ! {
		return errUnsupportedType{got: reflect.TypeOf(), want: reflect.TypeOf("")}
	}
	,  := Hex()
	if  != nil {
		return 
	}
	* = HexColor()
	return nil
}

func ( *HexColor) () (driver.Value, error) {
	return Color(*).Hex(), nil
}

func ( errUnsupportedType) () string {
	return fmt.Sprintf("unsupported type: got %v, want a %s", .got, .want)
}

func ( *HexColor) ( []byte) error {
	var  string
	if  := json.Unmarshal(, &);  != nil {
		return 
	}

	var ,  = Hex()
	if  != nil {
		return 
	}
	* = HexColor()
	return nil
}

func ( HexColor) () ([]byte, error) {
	return json.Marshal(Color().Hex())
}

// Decode - deserialize function for https://github.com/kelseyhightower/envconfig
func ( *HexColor) ( string) error {
	var ,  = Hex()
	if  != nil {
		return 
	}
	* = HexColor()
	return nil
}