var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import DatabaseService from "./DatabaseService";
import Model from "../../Models/DatabaseModels/WorkspaceSetting";
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
export class Service extends DatabaseService {
    constructor() {
        super(Model);
    }
    async doesExist(data) {
        return ((await this.countBy({
            query: {
                projectId: data.projectId,
                workspaceType: data.workspaceType,
            },
            skip: 0,
            limit: 1,
            props: {
                isRoot: true,
            },
        })).toNumber() > 0);
    }
    async refreshSetting(data) {
        let workspaceSetting = await this.findOneBy({
            query: {
                projectId: data.projectId,
                workspaceType: data.workspaceType,
            },
            select: {
                _id: true,
            },
            props: {
                isRoot: true,
            },
        });
        if (!workspaceSetting) {
            workspaceSetting = new Model();
            workspaceSetting.projectId = data.projectId;
            workspaceSetting.settings = data.settings;
            workspaceSetting.workspaceType = data.workspaceType;
            await this.create({
                data: workspaceSetting,
                props: {
                    isRoot: true,
                },
            });
        }
        else {
            await this.updateOneById({
                id: workspaceSetting.id,
                data: {
                    settings: data.settings,
                },
                props: {
                    isRoot: true,
                },
            });
        }
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], Service.prototype, "doesExist", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], Service.prototype, "refreshSetting", null);
export default new Service();
//# sourceMappingURL=WorkspaceSettingService.js.map