"use strict";
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActivityTable = void 0;
const sql_tools_1 = require("@immich/sql-tools");
const decorators_1 = require("../../decorators");
const album_asset_table_1 = require("./album-asset.table");
const album_table_1 = require("./album.table");
const asset_table_1 = require("./asset.table");
const user_table_1 = require("./user.table");
let ActivityTable = class ActivityTable {
    id;
    createdAt;
    updatedAt;
    albumId;
    userId;
    assetId;
    comment;
    isLiked;
    updateId;
};
exports.ActivityTable = ActivityTable;
__decorate([
    (0, sql_tools_1.PrimaryGeneratedColumn)(),
    __metadata("design:type", Object)
], ActivityTable.prototype, "id", void 0);
__decorate([
    (0, sql_tools_1.CreateDateColumn)(),
    __metadata("design:type", Object)
], ActivityTable.prototype, "createdAt", void 0);
__decorate([
    (0, sql_tools_1.UpdateDateColumn)(),
    __metadata("design:type", Object)
], ActivityTable.prototype, "updatedAt", void 0);
__decorate([
    (0, sql_tools_1.ForeignKeyColumn)(() => album_table_1.AlbumTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE' }),
    __metadata("design:type", String)
], ActivityTable.prototype, "albumId", void 0);
__decorate([
    (0, sql_tools_1.ForeignKeyColumn)(() => user_table_1.UserTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE' }),
    __metadata("design:type", String)
], ActivityTable.prototype, "userId", void 0);
__decorate([
    (0, sql_tools_1.ForeignKeyColumn)(() => asset_table_1.AssetTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: true }),
    __metadata("design:type", Object)
], ActivityTable.prototype, "assetId", void 0);
__decorate([
    (0, sql_tools_1.Column)({ type: 'text', default: null }),
    __metadata("design:type", Object)
], ActivityTable.prototype, "comment", void 0);
__decorate([
    (0, sql_tools_1.Column)({ type: 'boolean', default: false }),
    __metadata("design:type", Object)
], ActivityTable.prototype, "isLiked", void 0);
__decorate([
    (0, decorators_1.UpdateIdColumn)({ index: true }),
    __metadata("design:type", Object)
], ActivityTable.prototype, "updateId", void 0);
exports.ActivityTable = ActivityTable = __decorate([
    (0, sql_tools_1.Table)('activity'),
    (0, decorators_1.UpdatedAtTrigger)('activity_updatedAt'),
    (0, sql_tools_1.Index)({
        name: 'activity_like_idx',
        columns: ['assetId', 'userId', 'albumId'],
        unique: true,
        where: '("isLiked" = true)',
    }),
    (0, sql_tools_1.Check)({
        name: 'activity_like_check',
        expression: `(comment IS NULL AND "isLiked" = true) OR (comment IS NOT NULL AND "isLiked" = false)`,
    }),
    (0, sql_tools_1.ForeignKeyConstraint)({
        columns: ['albumId', 'assetId'],
        referenceTable: () => album_asset_table_1.AlbumAssetTable,
        referenceColumns: ['albumId', 'assetId'],
        onUpdate: 'NO ACTION',
        onDelete: 'CASCADE',
    })
], ActivityTable);
//# sourceMappingURL=activity.table.js.map