import AnalyticsBaseModel from "./AnalyticsBaseModel/AnalyticsBaseModel";
import Route from "../../Types/API/Route";
import AnalyticsTableEngine from "../../Types/AnalyticsDatabase/AnalyticsTableEngine";
import AnalyticsTableName from "../../Types/AnalyticsDatabase/AnalyticsTableName";
import AnalyticsTableColumn from "../../Types/AnalyticsDatabase/TableColumn";
import TableColumnType from "../../Types/AnalyticsDatabase/TableColumnType";
import Permission from "../../Types/Permission";
export default class MonitorLog extends AnalyticsBaseModel {
    constructor() {
        const projectIdColumn = new AnalyticsTableColumn({
            key: "projectId",
            title: "Project ID",
            description: "ID of project",
            required: true,
            type: TableColumnType.ObjectID,
            isTenantId: true,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.MonitorViewer,
                    Permission.ReadProjectMonitor,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.CreateProjectMonitor,
                ],
                update: [],
            },
        });
        const monitorIdColumn = new AnalyticsTableColumn({
            key: "monitorId",
            title: "Monitor ID",
            description: "ID of the monitor which this logs belongs to",
            required: true,
            type: TableColumnType.ObjectID,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.MonitorViewer,
                    Permission.ReadProjectMonitor,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.CreateProjectMonitor,
                ],
                update: [],
            },
        });
        const timeColumn = new AnalyticsTableColumn({
            key: "time",
            codec: [{ codec: "DoubleDelta" }, { codec: "ZSTD", level: 1 }],
            title: "Time",
            description: "When was the log created?",
            required: true,
            type: TableColumnType.DateTime64,
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.MonitorViewer,
                    Permission.ReadProjectMonitor,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.CreateProjectMonitor,
                ],
                update: [],
            },
        });
        const logBodyColumn = new AnalyticsTableColumn({
            key: "logBody",
            title: "Log Body",
            description: "The body of the log",
            required: true,
            defaultValue: {},
            type: TableColumnType.JSON,
            codec: { codec: "ZSTD", level: 3 },
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.MonitorViewer,
                    Permission.ReadProjectMonitor,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.CreateProjectMonitor,
                ],
                update: [],
            },
        });
        const retentionDateColumn = new AnalyticsTableColumn({
            key: "retentionDate",
            codec: [{ codec: "DoubleDelta" }, { codec: "ZSTD", level: 1 }],
            title: "Retention Date",
            description: "Date after which this row is eligible for TTL deletion, computed at ingest time as time + service.retainTelemetryDataForDays",
            required: true,
            type: TableColumnType.Date,
            defaultValue: undefined,
        });
        super({
            tableName: AnalyticsTableName.MonitorLog,
            tableEngine: AnalyticsTableEngine.MergeTree,
            singularName: "Monitor Log",
            accessControl: {
                read: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.Viewer,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.MonitorViewer,
                    Permission.ReadProjectMonitor,
                ],
                create: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.CreateProjectMonitor,
                ],
                update: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.EditProjectMonitor,
                ],
                delete: [
                    Permission.ProjectOwner,
                    Permission.ProjectAdmin,
                    Permission.ProjectMember,
                    Permission.MonitorAdmin,
                    Permission.MonitorMember,
                    Permission.DeleteProjectMonitor,
                ],
            },
            pluralName: "Monitor Logs",
            crudApiPath: new Route("/monitor-log"),
            tableColumns: [
                projectIdColumn,
                monitorIdColumn,
                timeColumn,
                logBodyColumn,
                retentionDateColumn,
            ],
            projections: [],
            sortKeys: ["projectId", "time", "monitorId"],
            primaryKeys: ["projectId", "time", "monitorId"],
            partitionKey: "toYYYYMMDD(time)",
            tableSettings: "ttl_only_drop_parts = 1, non_replicated_deduplication_window = 10000",
            ttlExpression: "retentionDate DELETE",
            defaultSortColumn: "time",
        });
    }
    get projectId() {
        return this.getColumnValue("projectId");
    }
    set projectId(v) {
        this.setColumnValue("projectId", v);
    }
    get monitorId() {
        return this.getColumnValue("monitorId");
    }
    set monitorId(v) {
        this.setColumnValue("monitorId", v);
    }
    get time() {
        return this.getColumnValue("time");
    }
    set time(v) {
        this.setColumnValue("time", v);
    }
    get logBody() {
        return this.getColumnValue("logBody");
    }
    set logBody(v) {
        this.setColumnValue("logBody", v);
    }
    get retentionDate() {
        return this.getColumnValue("retentionDate");
    }
    set retentionDate(v) {
        this.setColumnValue("retentionDate", v);
    }
}
//# sourceMappingURL=MonitorLog.js.map