import io.codearte.jfairy.Fairy;
import io.codearte.jfairy.producer.person.Person;
import org.joda.time.DateTime;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class Main {
	private Boolean isCSV;

	public static void main(String[] args) throws Exception {
		Main m = new Main();

		m.generateCSVFile();
	}

	public String q(Object toQ) {
		if (!(toQ instanceof Boolean || toQ instanceof Integer || isCSV)) {
			return "\"" + toQ.toString() + "\"";
		}
		return toQ.toString();
	}

	public void generateCSVFile() throws IOException {
		isCSV = true;
		Fairy fairy = Fairy.create();
		FileOutputStream fop = null;
		File file;
		file = new File("C:/Users/User/Desktop/csv.txt");
		fop = new FileOutputStream(file);
		if (!file.exists()){
			file.createNewFile();
		}
		StringBuilder row = new StringBuilder();
		byte[] contentInBytes;

		for (int i = 0; i < 10; i++){
			Person person = fairy.person();
			row.append(q(person.getAddress())).append(",").
				append(q(person.getAge())).append(",").
				append(q(person.getCompany())).append(",").
				append(q(person.getCompanyEmail())).append(",").
				append(q(person.getDateOfBirth())).append(",").
				append(q(person.getEmail())).append(",").
				append(q(person.getFirstName())).append(",").
				append(q(person.getFullName())).append(",").
				append(q(person.getLastName())).append(",").
				append(q(person.getMiddleName())).append(",").
				append(q(person.getNationalIdentificationNumber())).append(",").
				append(q(person.getNationalIdentityCardNumber())).append(",").
				append(q(person.getPassportNumber())).append(",").
				append(q(person.getPassword())).append(",").
				append(q(person.getSex())).append(",").
				append(q(person.getTelephoneNumber())).append(",").
				append(q(person.getUsername())).append(",").
				append(q(person.isFemale())).append(",").
				append(q(person.isMale())).append(",");

			contentInBytes = row.toString().getBytes();
      row.setLength(0);
			fop.write(contentInBytes);
			fop.write(System.lineSeparator().getBytes());
			fop.flush();
			System.out.println(i);
		}
	}
}
