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 User from "./User";
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
import Route from "../../Types/API/Route";
import { PlanType } from "../../Types/Billing/SubscriptionPlan";
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import TableBillingAccessControl from "../../Types/Database/AccessControl/TableBillingAccessControl";
import ColumnLength from "../../Types/Database/ColumnLength";
import ColumnType from "../../Types/Database/ColumnType";
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
import IsPermissionsIf from "../../Types/Database/IsPermissionsIf";
import SlugifyColumn from "../../Types/Database/SlugifyColumn";
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, JoinColumn, ManyToOne } from "typeorm";
import EnableDocumentation from "../../Types/Database/EnableDocumentation";
import LlmType from "../../Types/LLM/LlmType";
let LlmProvider = class LlmProvider extends BaseModel {
    constructor() {
        super(...arguments);
        this.name = undefined;
        this.description = undefined;
        this.slug = undefined;
        this.llmType = undefined;
        this.apiKey = undefined;
        this.modelName = undefined;
        this.baseUrl = undefined;
        this.project = undefined;
        this.projectId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.isGlobalLlm = undefined;
        this.isDefault = undefined;
        this.costPerMillionTokensInUSDCents = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectLlm,
        ],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Name,
        canReadOnRelationQuery: true,
        title: "Name",
        description: "A friendly name for this LLM configuration.",
    }),
    Column({
        nullable: false,
        type: ColumnType.Name,
        length: ColumnLength.Name,
    }),
    __metadata("design:type", String)
], LlmProvider.prototype, "name", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectLlm,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Description",
        description: "Description of this LLM configuration.",
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
    }),
    __metadata("design:type", String)
], LlmProvider.prototype, "description", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [Permission.Public],
        update: [],
    }),
    TableColumn({
        required: true,
        unique: true,
        type: TableColumnType.Slug,
        computed: true,
        title: "Slug",
        description: "Friendly globally unique name for your object",
    }),
    Column({
        nullable: false,
        type: ColumnType.Slug,
        length: ColumnLength.Slug,
    }),
    __metadata("design:type", String)
], LlmProvider.prototype, "slug", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectLlm,
        ],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        title: "LLM Type",
        description: "The type of LLM provider (OpenAI, Azure OpenAI, Anthropic, Groq, Mistral, Ollama, etc.)",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], LlmProvider.prototype, "llmType", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.ProjectOwner, Permission.ProjectAdmin],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectLlm,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "API Key",
        description: "The API key for the LLM provider. Required for OpenAI, Azure OpenAI, Anthropic, Groq, and Mistral.",
        encrypted: true,
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
    }),
    __metadata("design:type", String)
], LlmProvider.prototype, "apiKey", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectLlm,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortText,
        title: "Model Name",
        description: "The name of the model to use (e.g., gpt-4, claude-3-opus, llama2).",
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], LlmProvider.prototype, "modelName", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectLlm,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortURL,
        title: "Base URL",
        description: "The base URL for the LLM API. Required for Azure OpenAI and Ollama, optional for others.",
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortURL,
        length: ColumnLength.ShortURL,
    }),
    __metadata("design:type", String)
], LlmProvider.prototype, "baseUrl", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.Public],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.Entity,
        required: false,
        modelType: Project,
        title: "Project",
        description: "The project this LLM belongs to. If null, it is a global LLM.",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], LlmProvider.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.Public],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        canReadOnRelationQuery: true,
        title: "Project ID",
        description: "ID of the project this LLM belongs to. If null, it is a global LLM.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmProvider.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({ type: TableColumnType.Entity, modelType: User }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], LlmProvider.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)
], LlmProvider.prototype, "deletedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.ProjectOwner],
        update: [],
    }),
    TableColumn({ type: TableColumnType.Entity, modelType: User }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "createdByUserId" }),
    __metadata("design:type", User)
], LlmProvider.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.ProjectOwner],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Created by User ID",
        description: "User ID who created this object (if this object was created by a User)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], LlmProvider.prototype, "createdByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({
        isDefaultValueColumn: true,
        required: true,
        type: TableColumnType.Boolean,
        canReadOnRelationQuery: true,
        title: "Is Global LLM",
        description: "Is this a global LLM that is available to all projects? Only admins can create global LLMs.",
        defaultValue: false,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        unique: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], LlmProvider.prototype, "isGlobalLlm", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectLlm,
        ],
    }),
    TableColumn({
        isDefaultValueColumn: true,
        required: true,
        type: TableColumnType.Boolean,
        title: "Is Default",
        description: "Is this the default LLM provider for the project? When set, the global LLM provider will not be used.",
        defaultValue: false,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        unique: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], LlmProvider.prototype, "isDefault", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [Permission.Public],
        update: [],
    }),
    TableColumn({
        isDefaultValueColumn: true,
        required: true,
        type: TableColumnType.Number,
        title: "Cost Per Million Tokens (USD Cents)",
        description: "Cost per million tokens in USD cents. Used for billing when using global LLM providers.",
        defaultValue: 0,
    }),
    Column({
        type: ColumnType.Number,
        nullable: false,
        default: 0,
    }),
    __metadata("design:type", Number)
], LlmProvider.prototype, "costPerMillionTokensInUSDCents", void 0);
LlmProvider = __decorate([
    EnableDocumentation(),
    TableBillingAccessControl({
        create: PlanType.Growth,
        read: PlanType.Free,
        update: PlanType.Growth,
        delete: PlanType.Free,
    }),
    IsPermissionsIf(Permission.Public, "projectId", null),
    TenantColumn("projectId"),
    CrudApiEndpoint(new Route("/llm-provider")),
    SlugifyColumn("name", "slug"),
    Entity({
        name: "LlmProvider",
    }),
    TableMetadata({
        tableName: "LlmProvider",
        singularName: "LLM Provider",
        pluralName: "LLM Providers",
        icon: IconProp.Bolt,
        tableDescription: "Manage LLM Provider configurations. Connect to OpenAI, Azure OpenAI, Anthropic, Groq, Mistral, Ollama, or other LLM providers to enable AI features.",
    }),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectLlm,
        ],
        read: [
            Permission.Public,
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.SettingsViewer,
            Permission.ReadProjectLlm,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.DeleteProjectLlm,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectLlm,
        ],
    })
], LlmProvider);
export default LlmProvider;
//# sourceMappingURL=LlmProvider.js.map