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 ColumnAccessControl from "../../../Types/Database/AccessControl/ColumnAccessControl";
import ColumnLength from "../../../Types/Database/ColumnLength";
import ColumnType from "../../../Types/Database/ColumnType";
import SlugifyColumn from "../../../Types/Database/SlugifyColumn";
import TableColumn from "../../../Types/Database/TableColumn";
import TableColumnType from "../../../Types/Database/TableColumnType";
import MimeType from "../../../Types/File/MimeType";
import ObjectID from "../../../Types/ObjectID";
import Permission from "../../../Types/Permission";
import BaseModel from "./DatabaseBaseModel";
import { Column } from "typeorm";
let FileModel = class FileModel extends BaseModel {
    constructor(id) {
        super(id);
        this.file = undefined;
        this.name = undefined;
        this.fileType = undefined;
        this.slug = undefined;
        this.isPublic = undefined;
        /*
         * High-entropy token used to address a file via /file/image/access-token/:token.
         * Generated server-side on create. Unguessable replacement for the
         * file id when embedding files in markdown so that ObjectIDs are not
         * enumerable. Combined with the isPublic flag the token route only
         * serves anonymous requests when isPublic is true; otherwise an
         * authenticated session is required.
         */
        this.imageAccessToken = undefined;
    }
    isFileModel() {
        return true;
    }
};
__decorate([
    ColumnAccessControl({
        create: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        read: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.File,
        canReadOnRelationQuery: true,
    }),
    Column({
        nullable: false,
        type: ColumnType.File,
    }),
    __metadata("design:type", Buffer)
], FileModel.prototype, "file", void 0);
__decorate([
    ColumnAccessControl({
        create: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        read: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        title: "Name",
        description: "Any friendly name of this object",
        canReadOnRelationQuery: true,
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], FileModel.prototype, "name", void 0);
__decorate([
    ColumnAccessControl({
        create: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        read: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], FileModel.prototype, "fileType", void 0);
__decorate([
    ColumnAccessControl({
        create: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        read: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        update: [],
    }),
    TableColumn({
        required: true,
        unique: true,
        type: TableColumnType.Slug,
        canReadOnRelationQuery: true,
    }),
    Column({
        nullable: false,
        type: ColumnType.Slug,
        length: ColumnLength.Slug,
    }),
    __metadata("design:type", String)
], FileModel.prototype, "slug", void 0);
__decorate([
    ColumnAccessControl({
        create: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        read: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        update: [],
    }),
    TableColumn({
        required: true,
        isDefaultValueColumn: true,
        type: TableColumnType.Slug,
        canReadOnRelationQuery: true,
    }),
    Column({
        nullable: false,
        default: true,
        type: ColumnType.Slug,
        length: ColumnLength.Slug,
    }),
    __metadata("design:type", Boolean)
], FileModel.prototype, "isPublic", void 0);
__decorate([
    ColumnAccessControl({
        create: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        read: [Permission.CurrentUser, Permission.AuthenticatedRequest],
        update: [],
    }),
    TableColumn({
        required: false,
        unique: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
    }),
    Column({
        nullable: true,
        unique: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], FileModel.prototype, "imageAccessToken", void 0);
FileModel = __decorate([
    SlugifyColumn("name", "slug"),
    __metadata("design:paramtypes", [ObjectID])
], FileModel);
export default FileModel;
//# sourceMappingURL=FileModel.js.map