"use strict";
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
    function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
    var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
    var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
    var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
    var _, done = false;
    for (var i = decorators.length - 1; i >= 0; i--) {
        var context = {};
        for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
        for (var p in contextIn.access) context.access[p] = contextIn.access[p];
        context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
        var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
        if (kind === "accessor") {
            if (result === void 0) continue;
            if (result === null || typeof result !== "object") throw new TypeError("Object expected");
            if (_ = accept(result.get)) descriptor.get = _;
            if (_ = accept(result.set)) descriptor.set = _;
            if (_ = accept(result.init)) initializers.unshift(_);
        }
        else if (_ = accept(result)) {
            if (kind === "field") initializers.unshift(_);
            else descriptor[key] = _;
        }
    }
    if (target) Object.defineProperty(target, contextIn.name, descriptor);
    done = true;
};
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
    var useValue = arguments.length > 2;
    for (var i = 0; i < initializers.length; i++) {
        value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
    }
    return useValue ? value : void 0;
};
var __setFunctionName = (this && this.__setFunctionName) || function (f, name, prefix) {
    if (typeof name === "symbol") name = name.description ? "[".concat(name.description, "]") : "";
    return Object.defineProperty(f, "name", { configurable: true, value: prefix ? "".concat(prefix, " ", name) : name });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.History = void 0;
var typeorm_1 = require("typeorm");
var enums_1 = require("../../common/enums");
var user_entity_1 = require("../../users/entities/user.entity");
var History = function () {
    var _classDecorators = [(0, typeorm_1.Entity)('history'), (0, typeorm_1.Unique)(['userId', 'contentId', 'contentType'])];
    var _classDescriptor;
    var _classExtraInitializers = [];
    var _classThis;
    var _id_decorators;
    var _id_initializers = [];
    var _id_extraInitializers = [];
    var _userId_decorators;
    var _userId_initializers = [];
    var _userId_extraInitializers = [];
    var _user_decorators;
    var _user_initializers = [];
    var _user_extraInitializers = [];
    var _contentId_decorators;
    var _contentId_initializers = [];
    var _contentId_extraInitializers = [];
    var _contentType_decorators;
    var _contentType_initializers = [];
    var _contentType_extraInitializers = [];
    var _progressSeconds_decorators;
    var _progressSeconds_initializers = [];
    var _progressSeconds_extraInitializers = [];
    var _totalSeconds_decorators;
    var _totalSeconds_initializers = [];
    var _totalSeconds_extraInitializers = [];
    var _watchedAt_decorators;
    var _watchedAt_initializers = [];
    var _watchedAt_extraInitializers = [];
    var History = _classThis = /** @class */ (function () {
        function History_1() {
            this.id = __runInitializers(this, _id_initializers, void 0);
            this.userId = (__runInitializers(this, _id_extraInitializers), __runInitializers(this, _userId_initializers, void 0));
            this.user = (__runInitializers(this, _userId_extraInitializers), __runInitializers(this, _user_initializers, void 0));
            this.contentId = (__runInitializers(this, _user_extraInitializers), __runInitializers(this, _contentId_initializers, void 0));
            this.contentType = (__runInitializers(this, _contentId_extraInitializers), __runInitializers(this, _contentType_initializers, void 0));
            this.progressSeconds = (__runInitializers(this, _contentType_extraInitializers), __runInitializers(this, _progressSeconds_initializers, void 0));
            this.totalSeconds = (__runInitializers(this, _progressSeconds_extraInitializers), __runInitializers(this, _totalSeconds_initializers, void 0));
            this.watchedAt = (__runInitializers(this, _totalSeconds_extraInitializers), __runInitializers(this, _watchedAt_initializers, void 0));
            __runInitializers(this, _watchedAt_extraInitializers);
        }
        return History_1;
    }());
    __setFunctionName(_classThis, "History");
    (function () {
        var _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
        _id_decorators = [(0, typeorm_1.PrimaryGeneratedColumn)('uuid')];
        _userId_decorators = [(0, typeorm_1.Column)()];
        _user_decorators = [(0, typeorm_1.ManyToOne)(function () { return user_entity_1.User; }, function (user) { return user.history; }, { onDelete: 'CASCADE' }), (0, typeorm_1.JoinColumn)({ name: 'userId' })];
        _contentId_decorators = [(0, typeorm_1.Column)('uuid')];
        _contentType_decorators = [(0, typeorm_1.Column)({ type: 'enum', enum: enums_1.HistoryContentType })];
        _progressSeconds_decorators = [(0, typeorm_1.Column)({ default: 0 })];
        _totalSeconds_decorators = [(0, typeorm_1.Column)({ default: 0 })];
        _watchedAt_decorators = [(0, typeorm_1.UpdateDateColumn)({ type: 'timestamptz' })];
        __esDecorate(null, null, _id_decorators, { kind: "field", name: "id", static: false, private: false, access: { has: function (obj) { return "id" in obj; }, get: function (obj) { return obj.id; }, set: function (obj, value) { obj.id = value; } }, metadata: _metadata }, _id_initializers, _id_extraInitializers);
        __esDecorate(null, null, _userId_decorators, { kind: "field", name: "userId", static: false, private: false, access: { has: function (obj) { return "userId" in obj; }, get: function (obj) { return obj.userId; }, set: function (obj, value) { obj.userId = value; } }, metadata: _metadata }, _userId_initializers, _userId_extraInitializers);
        __esDecorate(null, null, _user_decorators, { kind: "field", name: "user", static: false, private: false, access: { has: function (obj) { return "user" in obj; }, get: function (obj) { return obj.user; }, set: function (obj, value) { obj.user = value; } }, metadata: _metadata }, _user_initializers, _user_extraInitializers);
        __esDecorate(null, null, _contentId_decorators, { kind: "field", name: "contentId", static: false, private: false, access: { has: function (obj) { return "contentId" in obj; }, get: function (obj) { return obj.contentId; }, set: function (obj, value) { obj.contentId = value; } }, metadata: _metadata }, _contentId_initializers, _contentId_extraInitializers);
        __esDecorate(null, null, _contentType_decorators, { kind: "field", name: "contentType", static: false, private: false, access: { has: function (obj) { return "contentType" in obj; }, get: function (obj) { return obj.contentType; }, set: function (obj, value) { obj.contentType = value; } }, metadata: _metadata }, _contentType_initializers, _contentType_extraInitializers);
        __esDecorate(null, null, _progressSeconds_decorators, { kind: "field", name: "progressSeconds", static: false, private: false, access: { has: function (obj) { return "progressSeconds" in obj; }, get: function (obj) { return obj.progressSeconds; }, set: function (obj, value) { obj.progressSeconds = value; } }, metadata: _metadata }, _progressSeconds_initializers, _progressSeconds_extraInitializers);
        __esDecorate(null, null, _totalSeconds_decorators, { kind: "field", name: "totalSeconds", static: false, private: false, access: { has: function (obj) { return "totalSeconds" in obj; }, get: function (obj) { return obj.totalSeconds; }, set: function (obj, value) { obj.totalSeconds = value; } }, metadata: _metadata }, _totalSeconds_initializers, _totalSeconds_extraInitializers);
        __esDecorate(null, null, _watchedAt_decorators, { kind: "field", name: "watchedAt", static: false, private: false, access: { has: function (obj) { return "watchedAt" in obj; }, get: function (obj) { return obj.watchedAt; }, set: function (obj, value) { obj.watchedAt = value; } }, metadata: _metadata }, _watchedAt_initializers, _watchedAt_extraInitializers);
        __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
        History = _classThis = _classDescriptor.value;
        if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        __runInitializers(_classThis, _classExtraInitializers);
    })();
    return History = _classThis;
}();
exports.History = History;
