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 { compose } from '@adonisjs/core/helpers';
import { BaseModel, beforeCreate, column } from '@adonisjs/lucid/orm';
import { VineModel } from '@akago/vine-lucid';
import vine from '@vinejs/vine';
import { randomUUID } from 'crypto';
import _ from 'lodash';
import { DateTime } from 'luxon';
import '../../lib/vine_types/vine_dateiso.js';
export const AKNakedModelMixin = (superclass) => {
    return class extends superclass {
        static excludeFromUpdate = [];
        static secondaryKey;
        static get secondaryKeys() {
            if (typeof this.secondaryKey === 'string') {
                return [this.secondaryKey];
            }
            else if (_.isArray(this.secondaryKey)) {
                return this.secondaryKey;
            }
            else {
                return [];
            }
        }
        static get keys() {
            return [this.primaryKey, ...this.secondaryKeys];
        }
    };
};
export const AKNakedModel = compose(BaseModel, AKNakedModelMixin);
export const AKIdModelMixin = (superclass) => {
    class AKIdModel extends superclass {
        static primaryKey = 'id';
        static selfAssignPrimaryKey = true;
        static excludeFromUpdate = [...super.excludeFromUpdate, 'id'];
        static assignUuid(object) {
            object.id = randomUUID();
        }
    }
    __decorate([
        VineModel(vine.string().uuid()),
        column(),
        __metadata("design:type", String)
    ], AKIdModel.prototype, "id", void 0);
    __decorate([
        beforeCreate(),
        __metadata("design:type", Function),
        __metadata("design:paramtypes", [Object]),
        __metadata("design:returntype", void 0)
    ], AKIdModel, "assignUuid", null);
    return AKIdModel;
};
export const AKModel = compose(AKNakedModel, AKIdModelMixin);
export const AKAuditableModelMixin = (superclass) => {
    class AKAuditableModel extends superclass {
        static excludeFromUpdate = [...super.excludeFromUpdate, 'createdAt', 'updatedAt'];
    }
    __decorate([
        VineModel(vine.dateIso()),
        column.dateTime({ autoCreate: true }),
        __metadata("design:type", DateTime)
    ], AKAuditableModel.prototype, "createdAt", void 0);
    __decorate([
        VineModel(vine.dateIso()),
        column.dateTime({ autoCreate: true, autoUpdate: true }),
        __metadata("design:type", Object)
    ], AKAuditableModel.prototype, "updatedAt", void 0);
    return AKAuditableModel;
};
export const AKAuditableModel = compose(AKModel, AKAuditableModelMixin);
//# sourceMappingURL=model.js.map