import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Types } from 'mongoose';
import { ObjectType, Field, ID, Int } from '@nestjs/graphql';
import { Base, CreatedBase } from '@/models/base.model';
import { Person } from '@/models/person.model';
import { Company } from '@/models/company.model';
import { BuildTypes } from './build-types.model';

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

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

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

    @Field()
    @Prop({ required: true })
    startDate: Date;

    @Field()
    @Prop({ required: true })
    stopDate: Date;

    @Field()
    @Prop({ required: true, default: 'TR0000000000000' })
    bankCode: string;

    @Field()
    @Prop({ required: true, default: '????' })
    xcomment: string;

}

@ObjectType()
export class BuildResponsible {

    @Field(() => String, { nullable: true })
    @Prop({ type: String, default: '' })
    company?: string;

    @Field(() => String, { nullable: true })
    @Prop({ type: String, default: '' })
    person?: string;

}

@ObjectType()
export class BuildInfo {

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

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

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

    @Field(() => Int)
    @Prop({ required: true })
    maxFloor: number;

    @Field(() => Int)
    @Prop({ required: true })
    undergroundFloor: number;

    @Field()
    @Prop({ required: true })
    buildDate: Date;

    @Field()
    @Prop({ required: true })
    decisionPeriodDate: Date;

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

    @Field(() => Int)
    @Prop({ required: true })
    liftCount: number;

    @Field()
    @Prop({ required: true })
    heatingSystem: boolean;

    @Field()
    @Prop({ required: true })
    coolingSystem: boolean;

    @Field()
    @Prop({ required: true })
    hotWaterSystem: boolean;

    @Field(() => Int)
    @Prop({ required: true })
    blockServiceManCount: number;

    @Field(() => Int)
    @Prop({ required: true })
    securityServiceManCount: number;

    @Field(() => Int)
    @Prop({ required: true })
    garageCount: number;

    @Field(() => String, { nullable: true })
    @Prop({ required: false })
    managementRoomId?: string;

}

@ObjectType()
@Schema({ timestamps: true })
export class Build extends CreatedBase {

    @Field()
    readonly _id: string;

    @Field(() => BuildTypes)
    @Prop({ type: Types.ObjectId, ref: BuildTypes.name, required: true })
    buildType: Types.ObjectId;

    @Field(() => String, { nullable: true })
    @Prop({ required: true })
    collectionToken: string;

    @Field(() => BuildInfo, { nullable: true })
    @Prop({ type: BuildInfo, required: true })
    info: BuildInfo;

    @Field(() => String, { nullable: true })
    @Prop({ type: String })
    site?: string;

    @Field(() => String, { nullable: true })
    @Prop({ type: String })
    address?: string;

    @Field(() => [String], { nullable: true, defaultValue: [] })
    @Prop({ type: [String], default: [] })
    areas?: string[];

    @Field(() => [String], { nullable: true, defaultValue: [] })
    @Prop({ type: [String], default: [] })
    ibans?: string[];

    @Field(() => [BuildResponsible], { nullable: true, defaultValue: [] })
    @Prop({ type: [BuildResponsible], default: [] })
    responsibles?: BuildResponsible[];

}

export type BuildIbanDocument = BuildIban & Document;
export const BuildIbanSchema = SchemaFactory.createForClass(BuildIban);

export type BuildDocument = Build & Document;
export const BuildSchema = SchemaFactory.createForClass(Build);
