import { randomUUID } from "crypto";

interface Base {
    uuid: string;

    expiryStarts: Date;
    expiryEnds: Date;

    createdAt: Date;
    updatedAt: Date;

    isConfirmed: boolean;
    deleted: boolean;
    active: boolean;

    crypUuId: string;
    createdCredentialsToken: string;
    updatedCredentialsToken: string;
    confirmedCredentialsToken: string;
    isNotificationSend: boolean;
    isEmailSend: boolean;

    refInt: number;
    refId: string;
    replicationId: number;
}

const BaseSchema = {
    uuid: { type: String, required: false, unique: true, default: randomUUID },
    expiryStarts: { type: Date, required: false, default: () => new Date(Date.now()) },
    expiryEnds: { type: Date, required: false, default: () => new Date('2099-12-31') },
    isConfirmed: { type: Boolean, required: false, default: false },
    deleted: { type: Boolean, required: false, default: false },
    active: { type: Boolean, required: false, default: true },
    crypUuId: { type: String, required: false, default: randomUUID },
    createdCredentialsToken: { type: String, required: false, default: randomUUID },
    updatedCredentialsToken: { type: String, required: false, default: randomUUID },
    confirmedCredentialsToken: { type: String, required: false, default: randomUUID },
    isNotificationSend: { type: Boolean, required: false, default: false },
    isEmailSend: { type: Boolean, required: false, default: false },
    refInt: { type: Number, required: false, default: 0 },
    refId: { type: String, required: false, default: randomUUID },
    replicationId: { type: Number, required: false, default: 0 },
};

export { BaseSchema };
export type { Base };