/*
 * Copyright (c) 2013 Codearte
 */
package eu.codearte.fairyland.producer;

import eu.codearte.fairyland.DataMaster;
import eu.codearte.fairyland.producer.person.Person;

import static eu.codearte.fairyland.DataMaster.PERSONAL_EMAIL;
import static org.apache.commons.lang3.StringUtils.lowerCase;

public class PersonProducer extends FairyProducer {

  public PersonProducer(RandomDataGenerator generator, RandomGenerator random) {
    super(generator, random);
    generate();
  }

  public Person generate() {
    return generate(Person.Sex.male);
  }

  public Person generate(Person.Sex selectedSex) {
    String firstName = generator.getValuesOfType(DataMaster.FIRST_NAME, selectedSex.name());
    Person.Sex sex = selectedSex;
    String lastName = generator.getValues(DataMaster.LAST_NAME);
    String email = generateEmail(firstName, lastName);
    return new Person(firstName, lastName, email, sex);
  }

  private String generateEmail(String firstName, Object lastName) {
    String temp = "";
    if (random.trueOrFalse()) {
      temp = firstName;
      if (random.trueOrFalse()) {
        temp += ".";
      }
    }
    return lowerCase(temp + lastName + "@" + generator.getValues(PERSONAL_EMAIL));
  }

}

@@ -230,16 +230,156 @@
 _EMAIL;%0A
+import static eu.codearte.fairyland.producer.person.Person.Sex.female;%0Aimport static eu.codearte.fairyland.producer.person.Person.Sex.male;%0A
 import s
@@ -671,24 +671,109 @@
 ate(
-Person.Sex.male)
+randomSex());%0A  %7D%0A%0A  private Person.Sex randomSex() %7B%0A    return random.trueOrFalse() ? male : female
 ;%0A  
@@ -813,24 +813,16 @@
 n.Sex se
-lectedSe
 x) %7B%0A   
@@ -892,24 +892,16 @@
 NAME, se
-lectedSe
 x.name()
@@ -907,42 +907,8 @@
 ));%0A
-    Person.Sex sex = selectedSex;%0A
     

Fix generating persons