import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import { ObjectType, Field, ID, GraphQLISODateTime } from '@nestjs/graphql';
import { Base } from '@/models/base.model';

@Schema({ timestamps: true })
@ObjectType()
export class Person extends Base {

    @Field(() => ID)
    _id: string;

    @Prop({ required: true })
    @Field()
    firstName: string;

    @Prop({ required: true })
    @Field()
    surname: string;

    @Prop({ required: false })
    @Field()
    middleName: string;

    @Prop({ required: true })
    @Field()
    sexCode: string;

    @Prop({ required: false })
    @Field()
    personRef: string;

    @Prop({ required: false })
    @Field()
    personTag: string;

    @Prop({ required: true })
    @Field()
    fatherName: string;

    @Prop({ required: true })
    @Field()
    motherName: string;

    @Prop({ required: true })
    @Field()
    countryCode: string;

    @Prop({ required: true, unique: true })
    @Field()
    nationalIdentityId: string;

    @Prop({ required: true })
    @Field()
    birthPlace: string;

    @Prop({ required: true })
    @Field(() => GraphQLISODateTime)
    birthDate: Date;

    @Prop({ required: true })
    @Field()
    taxNo: string;

    @Prop({ required: false })
    @Field()
    birthname: string;
}

export type PersonDocument = Person & Document;
export const PersonSchema = SchemaFactory.createForClass(Person);

// PersonSchema.index({ firstName: 1, surname: 1, middleName: 1 }, { unique: true });
// PersonSchema.index({ nationalIdentityId: 1 }, { unique: true });
