import { AbstractRepository } from '@crosslab/service-common';
import { InstantiableBrowserDeviceModel } from '../../model.js';
export class InstantiableBrowserDeviceRepository extends AbstractRepository {
    dependencies = {};
    constructor() {
        super('Instantiable Browser Device');
    }
    dependenciesMet() {
        if (!this.dependencies.deviceOverview)
            return false;
        return true;
    }
    initialize(entityManager) {
        this.repository = entityManager.getRepository(InstantiableBrowserDeviceModel);
    }
    async create(data) {
        const model = await super.create(data);
        model.type = 'edge instantiable';
        return model;
    }
    async write(model, data) {
        if (!this.isInitialized())
            this.throwUninitializedRepositoryError();
        const { type: _type, codeUrl, description: _description, isPublic: _isPublic, name: _name, owner: _owner, services, viewer: _viewer, ...additionalAttributes } = { ...model.additionalAttributes, ...data };
        await this.dependencies.deviceOverview.write(model, data);
        if (codeUrl)
            model.codeUrl = codeUrl;
        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: 'edge instantiable',
            codeUrl: model.codeUrl,
            services: model.services ?? undefined,
        };
    }
}
//# sourceMappingURL=instantiableBrowserDevice.js.map