// This is not autogenerated.
package core

import (
	"database/sql/driver"
	"encoding/json"
	"fmt"
)

// GormDataType returns the data type for GORM to use when creating the database column.
func (m MapObject) GormDataType() string {
	return "text"
}

// Value implements the driver.Valuer interface, serializing MapObject as a JSON string.
func (m MapObject) Value() (driver.Value, error) {
	if m == nil {
		return nil, nil
	}
	b, err := json.Marshal(m)
	if err != nil {
		return nil, err
	}
	return string(b), nil
}

// Scan implements the sql.Scanner interface, deserializing a JSON string into MapObject.
func (m *MapObject) Scan(value interface{}) error {
	if value == nil {
		*m = nil
		return nil
	}
	var bytes []byte
	switch v := value.(type) {
	case []byte:
		bytes = v
	case string:
		bytes = []byte(v)
	default:
		return fmt.Errorf("cannot scan type %T into MapObject", value)
	}
	result := make(MapObject)
	if err := json.Unmarshal(bytes, &result); err != nil {
		return err
	}
	*m = result
	return nil
}
