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 RumApplication from "./RumApplication";
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 the client platforms a RUM application is seen on
 * (browser.platform / device.model.identifier), upserted from the telemetry
 * ingest pipeline; not user-editable. Deliberately coarse (by platform, not
 * per end-user device) to avoid a cardinality explosion.
 */
const READ_PERMISSIONS = [
    Permission.ProjectOwner,
    Permission.ProjectAdmin,
    Permission.ProjectMember,
    Permission.Viewer,
    Permission.SettingsAdmin,
    Permission.SettingsMember,
    Permission.SettingsViewer,
    Permission.ReadRumApplication,
];
let RumApplicationClient = class RumApplicationClient extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.rumApplication = undefined;
        this.rumApplicationId = undefined;
        this.clientName = undefined;
        this.clientType = 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 client belongs to.",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], RumApplicationClient.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 client belongs to.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], RumApplicationClient.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        manyToOneRelationColumn: "rumApplicationId",
        type: TableColumnType.Entity,
        modelType: RumApplication,
        title: "RUM Application",
        description: "Application this client belongs to.",
    }),
    ManyToOne(() => {
        return RumApplication;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "rumApplicationId" }),
    __metadata("design:type", RumApplication)
], RumApplicationClient.prototype, "rumApplication", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "RUM Application ID",
        description: "ID of the application this client belongs to.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], RumApplicationClient.prototype, "rumApplicationId", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Client Name",
        description: "Coarse client identifier (browser.platform or device.model.identifier).",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], RumApplicationClient.prototype, "clientName", void 0);
__decorate([
    ColumnAccessControl({ create: [], read: READ_PERMISSIONS, update: [] }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Client Type",
        description: "Whether this client is a browser or mobile device.",
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], RumApplicationClient.prototype, "clientType", 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 client was last observed.",
    }),
    Column({
        nullable: false,
        type: ColumnType.Date,
    }),
    __metadata("design:type", Date)
], RumApplicationClient.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)
], RumApplicationClient.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)
], RumApplicationClient.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)
], RumApplicationClient.prototype, "deletedByUserId", void 0);
RumApplicationClient = __decorate([
    TenantColumn("projectId"),
    TableAccessControl({
        create: [],
        read: READ_PERMISSIONS,
        update: [],
        delete: [],
    }),
    CrudApiEndpoint(new Route("/rum-application-client")),
    TableMetadata({
        tableName: "RumApplicationClient",
        singularName: "RUM Application Client",
        pluralName: "RUM Application Clients",
        icon: IconProp.Globe,
        tableDescription: "Live inventory of client platforms (browser / device) a RUM application is seen on, as last reported via OpenTelemetry. Coarse by platform, not per end-user device. Populated by the ingest pipeline; not user-editable.",
    }),
    Index(["projectId", "rumApplicationId", "clientName"], {
        unique: true,
    }),
    Entity({
        name: "RumApplicationClient",
    })
], RumApplicationClient);
export default RumApplicationClient;
//# sourceMappingURL=RumApplicationClient.js.map