import { AbstractRepository } from '@crosslab/service-common';
import { InstantiableCloudDeviceModel } from '../../model.js';
export class InstantiableCloudDeviceRepository extends AbstractRepository {
    dependencies = {};
    constructor() {
        super('Instantiable Cloud Device');
    }
    dependenciesMet() {
        if (!this.dependencies.deviceOverview)
            return false;
        return true;
    }
    initialize(entityManager) {
        this.repository = entityManager.getRepository(InstantiableCloudDeviceModel);
    }
    async create(data) {
        const model = await super.create(data);
        model.type = 'cloud instantiable';
        return model;
    }
    async write(model, data) {
        if (!this.isInitialized())
            this.throwUninitializedRepositoryError();
        const { type: _type, description: _description, instantiateUrl, isPublic: _isPublic, name: _name, owner: _owner, services, viewer: _viewer, ...additionalAttributes } = { ...model.additionalAttributes, ...data };
        await this.dependencies.deviceOverview.write(model, data);
        if (instantiateUrl)
            model.instantiateUrl = instantiateUrl;
        if (services)
            model.services = services;
        model.additionalAttributes = additionalAttributes;
    }
    async format(model) {
        if (!this.isInitialized())
            this.throwUninitializedRepositoryError();
        return {
            ...model.additionalAttributes,
            ...(await this.dependencies.deviceOverview.format(model)),
            type: 'cloud instantiable',
            instantiateUrl: model.instantiateUrl,
            services: model.services ?? undefined,
        };
    }
}
//# sourceMappingURL=instantiableCloudDevice.js.map