from flask import current_app
from models import User
import datetime
import uuid

app = current_app
db = app.db


@app.cli.command("create-testdata")
def create_sample_users():
    users = [
        User(
            uuid=str(uuid.uuid4()),
            username=f"test{i}@idm.localhost",
            display_name=f"Test{i}",
            first_name=f"Test{i}",
            last_name="Achternaam",
            email=f"test{i}@testmail.test",
            phone="06-12345678",
            last_updated=datetime.datetime.now(),
            street="Teststraat",
            number=str(i),
            postal="1234 AB",
            city="Stad",
            country="Land",
            lat=51.84049936832415 - 0.01 * i / 5,
            lon=5.813714861947134 + 0.02 * (i % 5),
            birthdate=datetime.datetime.now().date() + datetime.timedelta(days=i % 40),
            include_in_views=True,
        )
        for i in range(100)
    ]
    for user in users:
        user.reset_carddav_password()
    # to test duplicate coordinates
    users[25].lat = users[24].lat
    users[25].lon = users[24].lon

    for user in users:
        db.session.add(user)
    db.session.commit()
