package entities

// DeviceType represents the type of device
type DeviceType string

const (
	DeviceTypeAndroid  DeviceType = "android"
	DeviceTypeIOS      DeviceType = "ios"
	DeviceTypePC       DeviceType = "pc"
	DeviceTypeServer   DeviceType = "server"
	DeviceTypeRecovery DeviceType = "recovery"
)

// DeviceInfo holds information about a participant's device
type DeviceInfo struct {
	DeviceType DeviceType `json:"device_type"`
	DeviceID   string     `json:"device_id"`
	Platform   string     `json:"platform"`
	AppVersion string     `json:"app_version"`
}

// NewDeviceInfo creates a new DeviceInfo
func NewDeviceInfo(deviceType DeviceType, deviceID, platform, appVersion string) DeviceInfo {
	return DeviceInfo{
		DeviceType: deviceType,
		DeviceID:   deviceID,
		Platform:   platform,
		AppVersion: appVersion,
	}
}

// IsServer checks if the device is a server
func (d DeviceInfo) IsServer() bool {
	return d.DeviceType == DeviceTypeServer
}

// IsMobile checks if the device is mobile
func (d DeviceInfo) IsMobile() bool {
	return d.DeviceType == DeviceTypeAndroid || d.DeviceType == DeviceTypeIOS
}

// IsRecovery checks if the device is a recovery device
func (d DeviceInfo) IsRecovery() bool {
	return d.DeviceType == DeviceTypeRecovery
}

// Validate validates the device info
// DeviceInfo is now optional - empty device info is valid
func (d DeviceInfo) Validate() error {
	// Allow empty DeviceInfo for server parties or anonymous participants
	// Only validate if DeviceType is provided
	if d.DeviceType != "" {
		// If DeviceType is set, validate it's a known type
		switch d.DeviceType {
		case DeviceTypeAndroid, DeviceTypeIOS, DeviceTypePC, DeviceTypeServer, DeviceTypeRecovery:
			return nil
		default:
			return ErrInvalidDeviceInfo
		}
	}
	return nil
}
