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 Service from "./Service";
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 Decimal from "../../Types/Decimal";
import IconProp from "../../Types/Icon/IconProp";
import ProductType from "../../Types/MeteredPlan/ProductType";
import ServiceType from "../../Types/Telemetry/ServiceType";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
export const DEFAULT_RETENTION_IN_DAYS = 15;
let TelemetryUsageBilling = class TelemetryUsageBilling extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.day = undefined; // this is of format DD-MM-YYYY
        this.productType = undefined;
        this.retainTelemetryDataForDays = undefined;
        this.dataIngestedInGB = undefined;
        this.totalCostInUSD = undefined;
        this.isReportedToBillingProvider = undefined;
        this.service = undefined;
        this.primaryEntityId = undefined;
        this.primaryEntityType = undefined;
        this.reportedToBillingProviderAt = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "projectId",
        type: TableColumnType.Entity,
        modelType: Project,
        title: "Project",
        description: "Relation to Project Resource in which this object belongs",
        example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], TelemetryUsageBilling.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Project ID",
        description: "ID of your OneUptime Project in which this object belongs",
        example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryUsageBilling.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Day",
        description: "Day of the month this usage billing was generated for",
        example: "12-12-2025",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], TelemetryUsageBilling.prototype, "day", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Product Type",
        description: "Product Type this usage billing was generated for",
        example: "Logs",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], TelemetryUsageBilling.prototype, "productType", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.Number,
        title: "Retain Telemetry Data For Days",
        description: "Number of days to retain telemetry data for this service.",
        defaultValue: DEFAULT_RETENTION_IN_DAYS,
        example: 30,
    }),
    Column({
        type: ColumnType.Number,
        nullable: true,
        unique: false,
        default: DEFAULT_RETENTION_IN_DAYS,
    }),
    __metadata("design:type", Number)
], TelemetryUsageBilling.prototype, "retainTelemetryDataForDays", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Number,
        canReadOnRelationQuery: true,
        title: "Data Ingested (in GB)",
        description: "Data Ingested in GB this usage billing was generated for",
        example: 125.5,
    }),
    Column({
        nullable: false,
        type: ColumnType.Decimal,
        transformer: Decimal.getDatabaseTransformer(),
    }),
    __metadata("design:type", Decimal)
], TelemetryUsageBilling.prototype, "dataIngestedInGB", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Number,
        canReadOnRelationQuery: true,
        title: "Total Cost in USD",
        description: "Total Cost in USD this usage billing was generated for",
        example: 45.99,
    }),
    Column({
        nullable: false,
        type: ColumnType.Decimal,
        transformer: Decimal.getDatabaseTransformer(),
    }),
    __metadata("design:type", Decimal)
], TelemetryUsageBilling.prototype, "totalCostInUSD", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Boolean,
        canReadOnRelationQuery: true,
        title: "Reported to Billing Provider",
        description: "Whether this usage billing was reported to billing provider or not (eg Stripe)",
        example: true,
    }),
    Column({
        nullable: false,
        type: ColumnType.Boolean,
        default: false,
    }),
    __metadata("design:type", Boolean)
], TelemetryUsageBilling.prototype, "isReportedToBillingProvider", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "primaryEntityId",
        type: TableColumnType.Entity,
        modelType: Service,
        title: "Service",
        description: "Relation to Service Resource in which this object belongs",
        example: "d4e5f6a7-b8c9-0123-def1-234567890123",
    }),
    ManyToOne(() => {
        return Service;
    }, {
        eager: false,
        nullable: true,
        /*
         * No DB-level foreign key. Telemetry that arrives without a
         * service.name is metered against a synthetic "unattributed"
         * bucket whose primaryEntityId is the projectId (ServiceType.Unknown),
         * which has no matching Service row — a FK would reject those
         * billing rows. The relation is kept for read-side joins; it
         * resolves to null for the unattributed bucket and the UI renders
         * a synthetic "Unknown Service" in its place.
         */
        createForeignKeyConstraints: false,
    }),
    JoinColumn({ name: "primaryEntityId" }),
    __metadata("design:type", Service)
], TelemetryUsageBilling.prototype, "service", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        title: "Service ID",
        description: "ID of your Service resource where this object belongs",
        example: "d4e5f6a7-b8c9-0123-def1-234567890123",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryUsageBilling.prototype, "primaryEntityId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Service Type",
        description: "Resource type that produced this telemetry (e.g. OpenTelemetry service, Host, DockerHost, KubernetesCluster, or Unknown for unattributed telemetry).",
        example: "OpenTelemetry",
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], TelemetryUsageBilling.prototype, "primaryEntityType", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Date,
        canReadOnRelationQuery: true,
        title: "Reported to Billing Provider At",
        description: "When this usage billing was reported to billing provider or not (eg Stripe)",
        example: "2025-12-12T10:00:00.000Z",
    }),
    Column({
        nullable: true,
        type: ColumnType.Date,
    }),
    __metadata("design:type", Date)
], TelemetryUsageBilling.prototype, "reportedToBillingProviderAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "createdByUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Created by User",
        description: "Relation to User who created this object (if this object was created by a User)",
        example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "createdByUserId" }),
    __metadata("design:type", User)
], TelemetryUsageBilling.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        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)",
        example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryUsageBilling.prototype, "createdByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        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)",
        example: "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], TelemetryUsageBilling.prototype, "deletedByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        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)",
        example: "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryUsageBilling.prototype, "deletedByUserId", void 0);
TelemetryUsageBilling = __decorate([
    TenantColumn("projectId"),
    TableAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ManageProjectBilling,
        ],
        delete: [],
        update: [],
    }),
    CrudApiEndpoint(new Route("/telemetry-usage-billing")),
    TableMetadata({
        tableName: "TelemetryUsageBilling",
        singularName: "Telemetry Usage Billing",
        pluralName: "Telemetry Usage Billings",
        icon: IconProp.Billing,
        tableDescription: "Stores historical usage billing data for your telemetry data like Logs, Metrics, Traces, and Exceptions.",
    }),
    Entity({
        name: "TelemetryUsageBilling",
    })
], TelemetryUsageBilling);
export default TelemetryUsageBilling;
//# sourceMappingURL=TelemetryUsageBilling.js.map