import { Prop } from '@nestjs/mongoose';
import { randomUUID } from 'crypto';
import { ObjectType, InputType, Field } from '@nestjs/graphql';

@ObjectType({ isAbstract: true })
export class Base {

    @Field({ nullable: true })
    @Prop({ default: () => randomUUID(), unique: true })
    uuid: string;

    @Field({ nullable: true })
    @Prop({ default: () => new Date(Date.now()) })
    createdAt: Date;

    @Field({ nullable: true })
    @Prop({ default: () => new Date(Date.now()) })
    updatedAt: Date;

    @Field({ nullable: true })
    @Prop({ default: false, required: false })
    isConfirmed?: boolean;

    @Field({ nullable: true })
    @Prop({ default: false, required: false })
    deleted?: boolean;

    @Field({ nullable: true })
    @Prop({ default: true, required: false })
    active?: boolean;

    @Field({ nullable: true })
    @Prop({ default: randomUUID })
    crypUuId: string;

    @Field({ nullable: true })
    @Prop({ default: randomUUID })
    createdCredentialsToken: string;

    @Field({ nullable: true })
    @Prop({ default: randomUUID })
    updatedCredentialsToken: string;

    @Field({ nullable: true })
    @Prop({ default: randomUUID })
    confirmedCredentialsToken: string;

    @Field({ nullable: true })
    @Prop({ default: false, required: false })
    isNotificationSend?: boolean;

    @Field({ nullable: true })
    @Prop({ default: false, required: false })
    isEmailSend?: boolean;

    @Field({ nullable: true })
    @Prop({ default: 0 })
    refInt: number;

    @Field({ nullable: true })
    @Prop({ default: randomUUID })
    refId: string;

    @Field({ nullable: true })
    @Prop({ default: 0 })
    replicationId: number;

    @Field({ nullable: true })
    @Prop({ default: () => new Date(Date.now()), required: false })
    expiryStarts?: Date;

    @Field({ nullable: true })
    @Prop({ default: () => new Date('2099-12-31'), required: false })
    expiryEnds?: Date;

}



@ObjectType({ isAbstract: true })
export class CreatedBase {

    @Field()
    @Prop({ default: () => new Date(Date.now()), required: false })
    createdAt?: Date;

    @Field()
    @Prop({ default: () => new Date(Date.now()), required: false })
    updatedAt?: Date;

}

@ObjectType({ isAbstract: true })
export class ExpiryBase {

    @Field()
    @Prop({ default: () => new Date(Date.now()), required: false })
    expiryStarts?: Date;

    @Field()
    @Prop({ default: () => new Date('2099-12-31'), required: false })
    expiryEnds?: Date;

}

@InputType()
export class ExpiryBaseInput {

    @Field({ nullable: true, defaultValue: new Date(Date.now()).toISOString() })
    expiryStarts?: Date;

    @Field({ nullable: false, defaultValue: new Date('2099-12-31').toISOString() })
    expiryEnds?: Date;

}

@ObjectType({ isAbstract: true })
export class ChangableBase {

    @Field()
    @Prop({ default: () => new Date(Date.now()), required: false })
    expiryStarts?: Date;

    @Field()
    @Prop({ default: () => new Date('2099-12-31'), required: false })
    expiryEnds?: Date;

    @Field()
    @Prop({ default: false, required: false })
    isConfirmed?: boolean;

    @Field()
    @Prop({ default: false, required: false })
    deleted?: boolean;

    @Field()
    @Prop({ default: true, required: false })
    active?: boolean;
}
