// SPDX-License-Identifier: Apache-2.0
import { V1Lease, V1LeaseSpec, V1MicroTime, V1ObjectMeta } from '@kubernetes/client-node';
import { NamespaceName } from '../../../../../types/namespace/namespace-name.js';
export class K8ClientLease {
    namespace;
    leaseName;
    holderIdentity;
    durationSeconds;
    acquireTime;
    renewTime;
    resourceVersion;
    constructor(namespace, leaseName, holderIdentity, durationSeconds, acquireTime, renewTime, resourceVersion) {
        this.namespace = namespace;
        this.leaseName = leaseName;
        this.holderIdentity = holderIdentity;
        this.durationSeconds = durationSeconds;
        this.acquireTime = acquireTime;
        this.renewTime = renewTime;
        this.resourceVersion = resourceVersion;
    }
    static fromV1Lease(v1Lease) {
        return new K8ClientLease(NamespaceName.of(v1Lease.metadata.namespace), v1Lease.metadata.name, v1Lease.spec.holderIdentity, v1Lease.spec.leaseDurationSeconds, v1Lease.spec.acquireTime, v1Lease.spec.renewTime, v1Lease.metadata.resourceVersion);
    }
    static toV1Lease(lease) {
        const v1Lease = new V1Lease();
        const metadata = new V1ObjectMeta();
        metadata.name = lease.leaseName;
        metadata.namespace = lease.namespace.name;
        metadata.resourceVersion = lease.resourceVersion;
        v1Lease.metadata = metadata;
        const spec = new V1LeaseSpec();
        spec.holderIdentity = lease.holderIdentity;
        spec.leaseDurationSeconds = lease.durationSeconds;
        spec.acquireTime = lease.acquireTime || new V1MicroTime();
        spec.renewTime = lease.renewTime;
        v1Lease.spec = spec;
        return v1Lease;
    }
}
//# sourceMappingURL=k8-client-lease.js.map