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 Project from "./Project";
import Incident from "./Incident";
import Alert from "./Alert";
import ScheduledMaintenance from "./ScheduledMaintenance";
import User from "./User";
import LlmProvider from "./LlmProvider";
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 EnableDocumentation from "../../Types/Database/EnableDocumentation";
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 LlmLogStatus from "../../Types/LlmLogStatus";
import LlmType from "../../Types/LLM/LlmType";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
let LlmLog = class LlmLog extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        // LLM Provider Relation
        this.llmProvider = undefined;
        this.llmProviderId = undefined;
        // Denormalized provider info for historical reference
        this.llmProviderName = undefined;
        this.llmType = undefined;
        this.modelName = undefined;
        this.isGlobalProvider = undefined;
        // Token usage
        this.totalTokens = undefined;
        // Cost tracking
        this.costInUSDCents = undefined;
        this.wasBilled = undefined;
        // Status
        this.status = undefined;
        this.statusMessage = undefined;
        // Feature identification
        this.feature = undefined;
        this.requestPrompt = undefined;
        this.responsePreview = undefined;
        // Related resources
        this.incident = undefined;
        this.incidentId = undefined;
        this.alert = undefined;
        this.alertId = undefined;
        this.scheduledMaintenance = undefined;
        this.scheduledMaintenanceId = undefined;
        // User who triggered the request
        this.user = undefined;
        this.userId = undefined;
        // Timestamps and duration
        this.requestStartedAt = undefined;
        this.requestCompletedAt = undefined;
        this.durationMs = undefined;
        // Deleted by user
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "projectId",
        type: TableColumnType.Entity,
        modelType: Project,
        title: "Project",
        description: "Relation to Project Resource in which this object belongs",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], LlmLog.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Project ID",
        description: "ID of your OneUptime Project in which this object belongs",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmLog.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "llmProviderId",
        type: TableColumnType.Entity,
        modelType: LlmProvider,
        title: "LLM Provider",
        description: "LLM Provider used for this API call",
    }),
    ManyToOne(() => {
        return LlmProvider;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "llmProviderId" }),
    __metadata("design:type", LlmProvider)
], LlmLog.prototype, "llmProvider", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        canReadOnRelationQuery: true,
        title: "LLM Provider ID",
        description: "ID of LLM Provider used for this API call",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmLog.prototype, "llmProviderId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortText,
        title: "LLM Provider Name",
        description: "Name of the LLM Provider at time of call",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], LlmLog.prototype, "llmProviderName", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortText,
        title: "LLM Type",
        description: "Type of LLM (OpenAI, Azure OpenAI, Anthropic, Groq, Mistral, Ollama)",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], LlmLog.prototype, "llmType", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortText,
        title: "Model Name",
        description: "Name of the model used (e.g., gpt-4, claude-3-opus)",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], LlmLog.prototype, "modelName", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Boolean,
        title: "Is Global Provider",
        description: "Was a global LLM provider used for this call?",
        canReadOnRelationQuery: false,
        isDefaultValueColumn: true,
        defaultValue: false,
    }),
    Column({
        nullable: false,
        type: ColumnType.Boolean,
        default: false,
    }),
    __metadata("design:type", Boolean)
], LlmLog.prototype, "isGlobalProvider", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Number,
        title: "Tokens Used",
        description: "Total tokens used (input + output)",
        canReadOnRelationQuery: false,
        isDefaultValueColumn: true,
        defaultValue: 0,
    }),
    Column({
        nullable: false,
        default: 0,
        type: ColumnType.Number,
    }),
    __metadata("design:type", Number)
], LlmLog.prototype, "totalTokens", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Number,
        title: "Cost (USD Cents)",
        description: "Total cost in USD cents",
        canReadOnRelationQuery: false,
        isDefaultValueColumn: true,
        defaultValue: 0,
    }),
    Column({
        nullable: false,
        default: 0,
        type: ColumnType.Number,
    }),
    __metadata("design:type", Number)
], LlmLog.prototype, "costInUSDCents", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Boolean,
        title: "Was Billed",
        description: "Was the project charged for this API call?",
        canReadOnRelationQuery: false,
        isDefaultValueColumn: true,
        defaultValue: false,
    }),
    Column({
        nullable: false,
        type: ColumnType.Boolean,
        default: false,
    }),
    __metadata("design:type", Boolean)
], LlmLog.prototype, "wasBilled", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        title: "Status",
        description: "Status of the LLM API call",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], LlmLog.prototype, "status", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Status Message",
        description: "Status Message (error details if failed)",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], LlmLog.prototype, "statusMessage", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortText,
        title: "Feature",
        description: "The feature that triggered this API call (e.g., IncidentPostmortem)",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], LlmLog.prototype, "feature", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.VeryLongText,
        title: "Request Prompt",
        description: "The prompt sent to the LLM (truncated)",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.VeryLongText,
    }),
    __metadata("design:type", String)
], LlmLog.prototype, "requestPrompt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.VeryLongText,
        title: "Response Preview",
        description: "Preview of the LLM response (truncated)",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.VeryLongText,
    }),
    __metadata("design:type", String)
], LlmLog.prototype, "responsePreview", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "incidentId",
        type: TableColumnType.Entity,
        modelType: Incident,
        title: "Incident",
        description: "Incident associated with this LLM call (if any)",
    }),
    ManyToOne(() => {
        return Incident;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "incidentId" }),
    __metadata("design:type", Incident)
], LlmLog.prototype, "incident", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        canReadOnRelationQuery: true,
        title: "Incident ID",
        description: "ID of Incident associated with this LLM call (if any)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmLog.prototype, "incidentId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "alertId",
        type: TableColumnType.Entity,
        modelType: Alert,
        title: "Alert",
        description: "Alert associated with this LLM call (if any)",
    }),
    ManyToOne(() => {
        return Alert;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "alertId" }),
    __metadata("design:type", Alert)
], LlmLog.prototype, "alert", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        canReadOnRelationQuery: true,
        title: "Alert ID",
        description: "ID of Alert associated with this LLM call (if any)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmLog.prototype, "alertId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "scheduledMaintenanceId",
        type: TableColumnType.Entity,
        modelType: ScheduledMaintenance,
        title: "Scheduled Maintenance",
        description: "Scheduled Maintenance associated with this LLM call (if any)",
    }),
    ManyToOne(() => {
        return ScheduledMaintenance;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "scheduledMaintenanceId" }),
    __metadata("design:type", ScheduledMaintenance)
], LlmLog.prototype, "scheduledMaintenance", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        canReadOnRelationQuery: true,
        title: "Scheduled Maintenance ID",
        description: "ID of Scheduled Maintenance associated with this LLM call (if any)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmLog.prototype, "scheduledMaintenanceId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "userId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "User",
        description: "User who triggered this LLM call (if any)",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "userId" }),
    __metadata("design:type", User)
], LlmLog.prototype, "user", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        canReadOnRelationQuery: true,
        title: "User ID",
        description: "ID of User who triggered this LLM call (if any)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmLog.prototype, "userId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Date,
        title: "Request Started At",
        description: "When the LLM request started",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.Date,
    }),
    __metadata("design:type", Date)
], LlmLog.prototype, "requestStartedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Date,
        title: "Request Completed At",
        description: "When the LLM request completed",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.Date,
    }),
    __metadata("design:type", Date)
], LlmLog.prototype, "requestCompletedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Number,
        title: "Duration (ms)",
        description: "Request duration in milliseconds",
        canReadOnRelationQuery: false,
    }),
    Column({
        nullable: true,
        type: ColumnType.Number,
    }),
    __metadata("design:type", Number)
], LlmLog.prototype, "durationMs", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "deletedByUserId",
        type: TableColumnType.Entity,
        title: "Deleted by User",
        modelType: User,
        description: "Relation to User who deleted this object (if this object was deleted by a User)",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], LlmLog.prototype, "deletedByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Deleted by User ID",
        description: "User ID who deleted this object (if this object was deleted by a User)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmLog.prototype, "deletedByUserId", void 0);
LlmLog = __decorate([
    EnableDocumentation(),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.ReadLlmLog,
        ],
        delete: [],
        update: [],
    }),
    CrudApiEndpoint(new Route("/llm-log")),
    Entity({
        name: "LlmLog",
    }),
    TableMetadata({
        tableName: "LlmLog",
        singularName: "LLM Log",
        pluralName: "LLM Logs",
        icon: IconProp.Bolt,
        tableDescription: "Logs of all the LLM API calls for AI features in this project.",
    })
], LlmLog);
export default LlmLog;
//# sourceMappingURL=LlmLog.js.map