package models

import "time"

// SObject is the neutral record payload shape shared across repo boundaries.
type SObject map[string]interface{}

func (s SObject) GetString(key string) string {
	if val, ok := s[key]; ok {
		if str, ok := val.(string); ok {
			return str
		}
	}
	return ""
}

func (s SObject) GetBool(key string) bool {
	if val, ok := s[key]; ok {
		if b, ok := val.(bool); ok {
			return b
		}
	}
	return false
}

func (s SObject) GetTime(key string) time.Time {
	if val, ok := s[key]; ok {
		if t, ok := val.(time.Time); ok {
			return t
		}
		if tStr, ok := val.(string); ok {
			parsed, _ := time.Parse(time.RFC3339, tStr)
			return parsed
		}
	}
	return time.Time{}
}

func (s SObject) Get(key string) interface{} {
	return s[key]
}
