func ToInt(v Value) (int64, error) {
	defaultValue := int64(0)
	switch v.Type() {
	case TypeNull:
		return defaultValue, nil
	case TypeBool:
		val, _ := v.asBool()
		if val {
			return 1, nil
		}
		return 0, nil
	case TypeInt:
		return v.asInt()
	case TypeFloat:
		val, _ := v.asFloat()
		if val >= MinConvFloat64 && val <= MaxConvFloat64 {
			return int64(val), nil
		}
		return defaultValue,
			fmt.Errorf("%v is out of bounds for int64 conversion", val)
	case TypeString:
		val, _ := v.asString()
		return strconv.ParseInt(val, 0, 64)
	case TypeTimestamp:
		val, _ := v.asTimestamp()
		seconds := time.Duration(val.Unix())
		return int64(seconds), nil
	default:
		return defaultValue,
			fmt.Errorf("cannot convert %T to int64", v)
	}
}
ToInt converts a given Value to an int64, if possible. The conversion
rules are as follows:

* Null: 0
* Bool: 0 if false, 1 if true
* Int: actual value
* Float: conversion as done by int64(value)
(values outside of valid int64 bounds will lead to an error)
* String: parsed integer with base 0 as per strconv.ParseInt
(values outside of valid int64 bounds will lead to an error)
* Blob: (error)
* Timestamp: the number of second elapsed since January 1, 1970 UTC.
* Array: (error)
* Map: (error)
package data
import (
	"encoding/base64"
	"fmt"
	"math"
	"strconv"
	"strings"
	"time"
)
const (
	MaxConvFloat64 = float64(math.MaxInt64)
	MinConvFloat64 = float64(math.MinInt64)
	errNilConversionFormat = "cannot convert nil to %v"
)
func AsBool(v Value) (bool, error) {
	if v == nil {
		return false, fmt.Errorf(errNilConversionFormat, TypeBool)
	}
	return v.asBool()
}
func AsInt(v Value) (int64, error) {
	if v == nil {
		return 0, fmt.Errorf(errNilConversionFormat, TypeInt)
	}
	return v.asInt()
}
func AsFloat(v Value) (float64, error) {
	if v == nil {
		return 0, fmt.Errorf(errNilConversionFormat, TypeFloat)
	}
	return v.asFloat()
}
func AsString(v Value) (string, error) {
	if v == nil {
		return "", fmt.Errorf(errNilConversionFormat, TypeString)
	}
	return v.asString()
}
func AsBlob(v Value) ([]byte, error) {
	if v == nil {
		return nil, fmt.Errorf(errNilConversionFormat, TypeBlob)
	}
	return v.asBlob()
}
func AsTimestamp(v Value) (time.Time, error) {
	if v == nil {
		return time.Time{}, fmt.Errorf(errNilConversionFormat, TypeTimestamp)
	}
	return v.asTimestamp()
}
func AsArray(v Value) (Array, error) {
	if v == nil {
		return nil, fmt.Errorf(errNilConversionFormat, TypeArray)
	}
	return v.asArray()
}
func AsMap(v Value) (Map, error) {
	if v == nil {
		return nil, fmt.Errorf(errNilConversionFormat, TypeMap)
	}
	return v.asMap()
}
func ToBool(v Value) (bool, error) {
	defaultValue := false
	switch v.Type() {
	case TypeNull:
		return defaultValue, nil
	case TypeBool:
		return v.asBool()
	case TypeInt:
		val, _ := v.asInt()
		return val != 0, nil
	case TypeFloat:
		val, _ := v.asFloat()
		return val != 0.0 && !math.IsNaN(val), nil
	case TypeString:
		val, _ := v.asString()
		val = strings.TrimSpace(val)  
		switch strings.ToLower(val) {
		case "t", "true", "y", "yes", "on", "1":
			return true, nil
		case "f", "false", "n", "no", "off", "0":
			return false, nil
		}
		return false, fmt.Errorf("invalid string as a bool literal: %v", val)
	case TypeBlob:
		val, _ := v.asBlob()
		return len(val) > 0, nil
	case TypeTimestamp:
		val, _ := v.asTimestamp()
		return !val.IsZero(), nil
	case TypeArray:
		val, _ := v.asArray()
		return len(val) > 0, nil
	case TypeMap:
		val, _ := v.asMap()
		return len(val) > 0, nil
	default:
		return defaultValue,
			fmt.Errorf("cannot convert %T to bool", v)
	}
}