import type { JsonObject } from '../../../../types/json.js'
import {
  normalizeCloudtentaclesDeviceId,
  normalizeCloudtentaclesDeviceType,
} from '../../../platforms/cloudtentacles/defaults.js'

export function normalizeAdminCloudtentaclesSourceConfigPayload(payload: JsonObject = {}) {
  const sourceKey = String(payload.sourceKey || payload.key || '').trim() || 'default'
  return {
    key: sourceKey,
    label: String(payload.label || '').trim(),
    enabled: payload.enabled !== false,
    baseUrl: String(payload.baseUrl || '').trim() || 'https://123.207.217.176',
    username: String(payload.username || '').trim(),
    password: String(payload.password || '').trim(),
    phone: String(payload.phone || '').trim(),
    deviceId: normalizeCloudtentaclesDeviceId(payload.deviceId),
    deviceType: normalizeCloudtentaclesDeviceType(payload.deviceType),
  }
}
