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 ServerlessFunction from "./ServerlessFunction";
import Project from "./Project";
import User from "./User";
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
import Route from "../../Types/API/Route";
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import ColumnLength from "../../Types/Database/ColumnLength";
import ColumnType from "../../Types/Database/ColumnType";
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
import TableColumn from "../../Types/Database/TableColumn";
import TableColumnType from "../../Types/Database/TableColumnType";
import TableMetadata from "../../Types/Database/TableMetadata";
import TenantColumn from "../../Types/Database/TenantColumn";
import IconProp from "../../Types/Icon/IconProp";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
/*
 * Live inventory of a single instance of a serverless function (faas.instance),
 * upserted from the telemetry ingest pipeline; not user-editable. Sparse —
 * only populated for collectors that emit the faas.instance resource attribute.
 */
const READ_PERMISSIONS = [
    Permission.ProjectOwner,
    Permission.ProjectAdmin,
    Permission.ProjectMember,
    Permission.Viewer,
    Permission.SettingsAdmin,
    Permission.SettingsMember,
    Permission.SettingsViewer,
    Permission.ReadServerlessFunction,
];
let ServerlessFunctionInstance = class ServerlessFunctionInstance extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.serverlessFunction = undefined;
        this.serverlessFunctionId = undefined;
        this.instanceName = undefined;
        this.lastSeenAt = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
    }
};
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        manyToOneRelationColumn: "projectId",
        type: TableColumnType.Entity,
        modelType: Project,
        title: "Project",
        description: "Relation to Project this instance belongs to.",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], ServerlessFunctionInstance.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Project ID",
        description: "ID of the Project this instance belongs to.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], ServerlessFunctionInstance.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        manyToOneRelationColumn: "serverlessFunctionId",
        type: TableColumnType.Entity,
        modelType: ServerlessFunction,
        title: "Serverless Function",
        description: "Function this instance belongs to.",
    }),
    ManyToOne(() => {
        return ServerlessFunction;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "serverlessFunctionId" }),
    __metadata("design:type", ServerlessFunction)
], ServerlessFunctionInstance.prototype, "serverlessFunction", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Serverless Function ID",
        description: "ID of the function this instance belongs to.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], ServerlessFunctionInstance.prototype, "serverlessFunctionId", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Instance Name",
        description: "faas.instance value identifying this function instance.",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], ServerlessFunctionInstance.prototype, "instanceName", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        required: true,
        type: TableColumnType.Date,
        canReadOnRelationQuery: true,
        title: "Last Seen At",
        description: "When telemetry for this instance was last observed.",
    }),
    Column({
        nullable: false,
        type: ColumnType.Date,
    }),
    __metadata("design:type", Date)
], ServerlessFunctionInstance.prototype, "lastSeenAt", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Created By User ID",
        description: "ID of the user who created this row (ingest writes as root).",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], ServerlessFunctionInstance.prototype, "createdByUserId", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        manyToOneRelationColumn: "deletedByUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Deleted By User",
        description: "Relation to the user who deleted this row.",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], ServerlessFunctionInstance.prototype, "deletedByUser", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Deleted By User ID",
        description: "ID of the user who deleted this row.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], ServerlessFunctionInstance.prototype, "deletedByUserId", void 0);
ServerlessFunctionInstance = __decorate([
    TenantColumn("projectId"),
    TableAccessControl({
        create: [],
        read: READ_PERMISSIONS,
        update: [],
        delete: [],
    }),
    CrudApiEndpoint(new Route("/serverless-function-instance")),
    TableMetadata({
        tableName: "ServerlessFunctionInstance",
        singularName: "Serverless Function Instance",
        pluralName: "Serverless Function Instances",
        icon: IconProp.Bolt,
        tableDescription: "Live inventory of serverless function instances (faas.instance), as last reported via OpenTelemetry. Populated by the ingest pipeline; not user-editable.",
    }),
    Index(["projectId", "serverlessFunctionId", "instanceName"], {
        unique: true,
    }),
    Entity({
        name: "ServerlessFunctionInstance",
    })
], ServerlessFunctionInstance);
export default ServerlessFunctionInstance;
//# sourceMappingURL=ServerlessFunctionInstance.js.map