package domain

import (
	"encoding/json"
	"fmt"
)

// Custom type for fields that can be string or int
type StringOrNumber string

func (s *StringOrNumber) UnmarshalJSON(data []byte) error {
	// Try as string
	var str string
	if err := json.Unmarshal(data, &str); err == nil {
		*s = StringOrNumber(str)
		return nil
	}

	// Try as number
	var num json.Number
	if err := json.Unmarshal(data, &num); err == nil {
		*s = StringOrNumber(num.String())
		return nil
	}

	return fmt.Errorf("StringOrNumber: cannot unmarshal %s", string(data))
}
