import { ObjectSerializer as InternalSerializer } from './gen/models/ObjectSerializer.js';
class KubernetesObject {
}
KubernetesObject.attributeTypeMap = [
    {
        name: 'apiVersion',
        baseName: 'apiVersion',
        type: 'string',
        format: '',
    },
    {
        name: 'kind',
        baseName: 'kind',
        type: 'string',
        format: '',
    },
    {
        name: 'metadata',
        baseName: 'metadata',
        type: 'V1ObjectMeta',
        format: '',
    },
];
const isKubernetesObject = (data) => !!data && typeof data === 'object' && 'apiVersion' in data && 'kind' in data;
/**
 * Wraps the ObjectSerializer to support custom resources and generic Kubernetes objects.
 */
export class ObjectSerializer extends InternalSerializer {
    static serialize(data, type, format = '') {
        const obj = InternalSerializer.serialize(data, type, format);
        if (obj !== data) {
            return obj;
        }
        if (!isKubernetesObject(data)) {
            return obj;
        }
        const instance = {};
        for (const attributeType of KubernetesObject.attributeTypeMap) {
            const value = data[attributeType.baseName];
            if (value !== undefined) {
                instance[attributeType.name] = InternalSerializer.serialize(data[attributeType.baseName], attributeType.type, attributeType.format);
            }
        }
        // add all unknown properties as is.
        for (const [key, value] of Object.entries(data)) {
            if (KubernetesObject.attributeTypeMap.find((t) => t.name === key)) {
                continue;
            }
            instance[key] = value;
        }
        return instance;
    }
    static deserialize(data, type, format = '') {
        const obj = InternalSerializer.deserialize(data, type, format);
        if (obj !== data) {
            // the serializer knows the type and already deserialized it.
            return obj;
        }
        if (!isKubernetesObject(data)) {
            return obj;
        }
        const instance = new KubernetesObject();
        for (const attributeType of KubernetesObject.attributeTypeMap) {
            const value = data[attributeType.baseName];
            if (value !== undefined) {
                instance[attributeType.name] = InternalSerializer.deserialize(data[attributeType.baseName], attributeType.type, attributeType.format);
            }
        }
        // add all unknown properties as is.
        for (const [key, value] of Object.entries(data)) {
            if (KubernetesObject.attributeTypeMap.find((t) => t.name === key)) {
                continue;
            }
            instance[key] = value;
        }
        return instance;
    }
}
//# sourceMappingURL=serializer.js.map