import {Context, Float, Int, Parent, ResolveField, Resolver} from '@nestjs/graphql';
import { Client } from '../../client';
import { UUID } from '../../global/scalars/UUID';
import {EventApparatus} from '../models/EventApparatus'
import {Apparatus} from '../../apparatus/models/Apparatus'
import {ApparatusService} from '../../apparatus/apparatus.service'

@Resolver(() => EventApparatus)
export class EventApparatusResolver {
  @ResolveField(() => UUID, { nullable: false })
  async _apparatus(
    @Context('client') client: Client,
    @Parent() parent: EventApparatus
  ): Promise<UUID> {
    return parent._apparatus as UUID;
  }

  @ResolveField(() => Apparatus, { nullable: false })
  async apparatus(
    @Context('client') client: Client,
    @Parent() parent: EventApparatus
  ): Promise<Apparatus> {
    return new ApparatusService().findOneById(parent._apparatus);
  }

  @ResolveField(() => Int, { nullable: false })
  async elements(
    @Context('client') client: Client,
    @Parent() parent: EventApparatus
  ): Promise<number> {
    return parent.elements;
  }

  @ResolveField(() => Float, { nullable: false })
  async bonus(
    @Context('client') client: Client,
    @Parent() parent: EventApparatus
  ): Promise<number> {
    return parent.bonus;
  }

  @ResolveField(() => Float, { nullable: false })
  async malus(
    @Context('client') client: Client,
    @Parent() parent: EventApparatus
  ): Promise<number> {
    return parent.malus;
  }
}