import random
from datetime import date, timedelta, datetime

from django.utils.timezone import utc


first_names_male = ['Leon', 'Lukas', 'Ben', 'Finn', 'Jonas', 'Paul',
                    'Max', 'Felix', 'Tim', 'Elias', 'Noah', 'Niklas', 'Julian',
                    'Simon', 'Alexander', 'Jannik', 'Tom', 'Erik', 'Florian',
                    'Nick', 'Nils', 'Henry', 'Lennox', 'Daniel', 'Adrian',
                    'Sebastian', 'Johannes', 'Robin', 'Aaron', 'Oskar',
                    'Theo', 'Gabriel', 'Lars', 'Jeremy', 'Dennis', 'Toni',
                    'Bennet', 'Luke', 'Christian']

first_names_female = ['Mia', 'Hannah', 'Lena', 'Lea', 'Emma', 'Anna', 'Leonnie',
                      'Emily', 'Laura', 'Marie', 'Sarah', 'Sofia', 'Maja', 'Amelie',
                      'Lusia', 'Johanna', 'Clara', 'Alina', 'Charlotte', 'Julia',
                      'Pia', 'Paula', 'Jana', 'Jasmin', 'Victoria', 'Fiona', 'Stella',
                      'Antonia', 'Annika', 'Helene', 'Marlene', 'Isabelle', 'Lotta',
                      'Eva', 'Celine', 'Vanessa', 'Ronja', 'Romy', 'Frieda', 'Nine',
                      'Nora', 'Mira', 'Alexandra']

last_names = ['Mueller', 'Schmidt', 'Schneider', 'Fischer', 'Weber', 'Meyer', 'Wagner',
              'Becker', 'Schulz', 'Hoffmann', 'Schaefer', 'Koch', 'Bauer', 'Richter',
              'Klein', 'Wolf', 'Schroeder', 'Neumann', 'Schwarz', 'Zimmermann',
              'Braun', 'Hartmann', 'Werner', 'Schmitz', 'Lehmann', 'Schulze',
              'Koehler', 'Walter', 'Huber', 'Peters', 'Fuchs', 'Lang', 'Scholz',
              'Kraus', 'Winter', 'Schuhmacher', 'Vogt', 'Kraemer', 'Jaeger', 'Sommer',
              'Heinrich', 'Bergmann', 'Busch', 'Pohl', 'Kuhn', 'Sauer', 'Pfeiffer',
              'Berthold', 'Furtwaengler', 'Ribery', 'Klausen']

mail_provider = ['gmail.com', 'web.de', 't-online.de', 'gmx.net', 'zoho.com', 'yahoo.com', 'mail.ru']

streets = ['Westring', 'Ostring', 'Fraunhoferstr.', 'Boschstr.', 'Ostring', 'Olfa-Palme Damm', 'Eckernfoerderstr.',
           'Gutenbergstr.', 'Dehnkestr.', 'Kronshagener Weg', 'Osloring', 'Juetlandring', 'Gerhardtstr.',
           'Bluecherplatz', 'Feldstr',
           'Yorckstr.', 'Gneissenaustr', 'Adolfplatz', 'Kiellinie', 'Andreas Gayk Str.', 'Sophienblatt', 'Ringstr',
           'Knooper Weg']

cities = ['Kiel', 'Husum', 'Flensburg', 'Luebeck', 'Neumuenster', 'Stade', 'Eckernfoerde', 'Tarp', 'Flintbek',
          'Bordesholm', 'Dresden', 'Rostock', 'Schwerin', 'Neubrandenburg', 'Wismar', 'Greifswald', 'Anklam', 'Waren',
          'Neustrelitz',
          'Leipzig', 'Erfurt', 'Goerlitz', 'Magdeburg', 'Potsdam', 'Berlin', 'Muenchen', 'Stuttgart', 'Ulm',
          'Nuernberg',
          'Ingolstadt', 'Tuebingen', 'Heidelberg', 'Mainz', 'Karlsruhe', 'Freiburg', 'Kaiserslautern', 'Wiesbaden',
          'Trier', 'Aachen',
          'Koeln', 'Duisburg', 'Gelsenkirchen', 'Duesseldorf', 'Hannover', 'Bremen', 'Emden', 'Kassel', 'Osnabrueck',
          'Bielefeld']

states = ['Schleswig-Holstein', 'Mecklenburg-Vorpommern', 'Brandenburg', 'Sachsen', 'Sachsen-Anhalt', 'Niedersachsen',
          'Thueringen', 'Bayern', 'Baden Wuerttemberg', 'Rheinland Pfalz', 'Hessen', 'Nordrhein Westfalen', 'Saarland']

countries = ['Schland', 'Daenemark', 'Schweden', 'Norwegen', 'Russland', 'United Kingdom', 'France', 'Spain',
             'Italien', 'Austria', 'Switzerland', 'Poland', 'Bosnia', 'Croatia', 'China', 'India', 'Japan',
             'Venezuela', 'Brasilia']

companies = ['Royal Dutch Shell', 'Wal-Mart', 'Exxon Mobil', 'British Petrol', 'Toyota', 'Total',
             'Volkswagen', 'Samsung', 'E.ON', 'Berkshire Hathaway', 'Chevron', 'Petrobas', 'Daimler',
             'Apple', 'Allianz', 'Hewlett-Packard', 'Oracle', 'NEC', 'Lufthansa']

categories = ['agriculture', 'chemical', 'automotive', 'stock-breeding', 'food', 'fishing', 'plastics']


def random_age():
    age = random.randint(18, 50)
    # :)
    return (date.today() - timedelta(days=age * 365)) - timedelta(days=random.randint(1, 365))


def random_date_before_now():
    return date.today() - timedelta(days=random.randint(30, 350))


def random_date_time_past():
    now = datetime.utcnow().replace(tzinfo=utc)
    now = now.replace(year=2011)
    return now - timedelta(days=random.randint(6, 180), minutes=random.randint(1, 59))


def random_measurement_time():
    return timedelta(minutes=random.randint(15, 25))


def random_phone():
    return '{0} / {1}'.format(random.randint(100, 900), random.randint(400000, 800000))


def random_street():
    return '{0} {1}'.format(random.choice(streets), random.randint(20, 120))


def random_reference():
    s = '{0}'.format(random.randint(1000000, 1999999))
    for x in range(3):
        s = s + random.choice(['A', 'Z', 'X'])
    return s


def random_company():
    c = random.choice(companies)
    companies.remove(c)
    return c


def random_department():
    return random.choice(['r&d', 'livestock', 'material research', 'fragrances'])


def generate_person(person_base_object):
    person_base_object.last_name = random.choice(last_names)
    if random.random() < 0.5:
        person_base_object.first_name = random.choice(first_names_male)
        person_base_object.gender = 'M'
    else:
        person_base_object.first_name = random.choice(first_names_female)
        person_base_object.gender = 'F'

    # randomly (with a low chance, forget about the correct gender...)
    if random.random() < 0.1:
        if random.random() < 0.5:
            person_base_object.gender = 'U'
        else:
            person_base_object.gender = 'N'


def generate_contact_data(contact_data_object):
    contact_data_object.phone = random_phone()
    contact_data_object.mobile = random_phone()


def mail_for_person(p):
    em = '{0}.{1}@{2}'.format(p.first_name, p.last_name, random.choice(mail_provider))
    return em.lower().replace(' ', '')


def random_title():
    return random.choice(['head of r&d', 'secretary', 'CEO', 'sales engineer', 'trainee'])


def random_ite():
    return 800.0 + random.random() * 1500.0


def generate_address(address_base_object):
    address_base_object.address = random_street()
    address_base_object.city = random.choice(cities)
    address_base_object.zip = random.randint(15000, 80000)
    address_base_object.state = random.choice(states)
    address_base_object.country = random.choice(countries)