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

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

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

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

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

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

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

    @Field(() => Float)
    @Prop({ required: true })
    areaGrossSize: number;

    @Field(() => Float)
    @Prop({ required: true })
    areaNetSize: number;

    @Field(() => Float)
    @Prop({ required: true })
    width: number;

    @Field(() => Float)
    @Prop({ required: true })
    size: number;

    @Field(() => ID, { nullable: true })
    @Prop({ type: Types.ObjectId, ref: 'Build', required: false })
    buildId?: Types.ObjectId;

    @Field(() => ID, { nullable: true })
    @Prop({ type: Types.ObjectId, ref: 'BuildType', required: false })
    partTypeId?: Types.ObjectId;

}

export type BuildAreaDocument = BuildArea & Document;
export const BuildAreaSchema = SchemaFactory.createForClass(BuildArea);
