import { Injectable } from '@nestjs/common';
import { Person } from './models/Person';
import { Client } from '../client';
import { v4 as uuid } from 'uuid';
import { EmailAddress } from '../global/scalars/EmailAddress'
import { secureHash } from '../generate'
import { Service } from '../global/service'

@Injectable()
export class PersonService extends Service<Person> {
  constructor() {
    super();
    this.collection = 'person';
  }

  async create(client: Client, givenName: string, familyName: string, email: EmailAddress, passwort: string): Promise<Person> {
    const neu = {
      givenName,
      familyName,
      email,
      passwort: await secureHash(passwort),
      confirmCode: uuid(),
    }

    return super.insert(client, neu);
  }
}