import csv
from faker import Faker
import datetime


def datagenerate(records, headers):
    fake = Faker('en_US')
    fake1 = Faker('en_GB')  # To generate phone numbers
    with open("People_data.csv", 'wt') as csvFile:
        writer = csv.DictWriter(csvFile,  delimiter=';', quotechar='"', fieldnames=headers)
        writer.writeheader()
        for i in range(records):
            full_name = fake.name()
            FLname = full_name.split(" ")
            Fname = FLname[0]
            Lname = FLname[1]
            domain_name = "@testDomain.com"
            userId = Fname + "." + Lname + domain_name
            # writer = csv.writer(csvFile, delimiter=';', quotechar='|', quoting=csv.QUOTE_MINIMAL)
            writer.writerow({
                "Email Id": userId,
                "Name": fake.name(),
                "Birth Date": fake.date(pattern="%d-%m-%Y", end_datetime=datetime.date(2000, 1, 1)),
                "Phone Number": fake1.phone_number(),
                "Additional Email Id": fake.email(),
                "Address": fake.address(),
                "Text": fake.sentence(10,20),
            })


if __name__ == '__main__':
    records = 50
    headers = ["Email Id", "Name", "Birth Date", "Phone Number", "Additional Email Id",
               "Address", "Text"]
    datagenerate(records, headers)
    print("CSV generation complete!")