import requests, random

BASE = "http://localhost:8001/api"

AVATARS = [
    "https://images.unsplash.com/photo-1653762378316-29106785b7b6?crop=entropy&cs=srgb&fm=jpg&q=85&w=600",
    "https://images.unsplash.com/photo-1673746310017-9a8893759d0f?crop=entropy&cs=srgb&fm=jpg&q=85&w=600",
    "https://images.unsplash.com/photo-1758272134548-47962a8e1b93?crop=entropy&cs=srgb&fm=jpg&q=85&w=600",
    "https://images.unsplash.com/photo-1500648767791-00dcc994a43e?crop=entropy&cs=srgb&fm=jpg&q=85&w=600",
    "https://images.unsplash.com/photo-1494790108377-be9c29b29330?crop=entropy&cs=srgb&fm=jpg&q=85&w=600",
    "https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?crop=entropy&cs=srgb&fm=jpg&q=85&w=600",
    "https://images.unsplash.com/photo-1438761681033-6461ffad8d80?crop=entropy&cs=srgb&fm=jpg&q=85&w=600",
    "https://images.unsplash.com/photo-1527980965255-d3b416303d12?crop=entropy&cs=srgb&fm=jpg&q=85&w=600",
]
INTERESTS = ["Travel","Music","Foodie","Fitness","Art","Gaming","Reading","Movies","Coffee","Hiking","Photography","Dancing","Yoga","Cooking","Pets","Wine"]
GENDERS = ["Woman","Man","Non-binary"]
ORIENT = ["Straight","Gay","Bisexual","Pansexual"]
LOOKING = ["Relationship","Casual","Friends","Networking"]
CITIES = ["New York","Los Angeles","San Francisco","Austin","Chicago","Seattle","Miami","Denver"]
JOBS = ["Designer","Software Engineer","Photographer","Marketing Lead","Barista","Nurse","Architect","Teacher","Chef","Founder"]
EDU = ["NYU","UCLA","Stanford","UT Austin","Berkeley","Parsons","MIT"]

people = [
    ("Maya Chen","maya@demo.com",27,0,"Coffee snob, weekend hiker, always planning the next trip."),
    ("Jordan Rivera","jordan@demo.com",29,1,"Live music + good tacos. Let's find the best spot in town."),
    ("Sofia Marsh","sofia@demo.com",25,0,"Artist & dog mom. Looking for someone to gallery-hop with."),
    ("Ethan Brooks","ethan@demo.com",31,1,"Runner, reader, terrible at pool but great company."),
    ("Aria Patel","aria@demo.com",26,0,"Yoga at sunrise, wine at sunset. Foodie for life."),
    ("Leo Nguyen","leo@demo.com",28,1,"Photographer chasing golden hour. Dog person."),
    ("Nina Kowalski","nina@demo.com",30,2,"Architect who loves dancing and bad puns."),
    ("Marcus Hill","marcus@demo.com",33,1,"Chef by trade, romantic by nature. I'll cook, you taste."),
]

tokens = {}
for i,(name,email,age,gidx,bio) in enumerate(people):
    r = requests.post(f"{BASE}/auth/register", json={"name":name,"email":email,"password":"Demo@123"})
    if r.status_code != 200:
        # already exists, login
        r = requests.post(f"{BASE}/auth/login", json={"email":email,"password":"Demo@123"})
        if r.status_code != 200:
            print("skip", email, r.text[:80]); continue
    data = r.json(); tok = data["token"]; tokens[email] = data["id"]
    h = {"Authorization": f"Bearer {tok}"}
    requests.put(f"{BASE}/profile", headers=h, json={
        "age": age, "gender": GENDERS[gidx], "orientation": random.choice(ORIENT),
        "looking_for": random.choice(LOOKING), "location": random.choice(CITIES),
        "occupation": random.choice(JOBS), "education": random.choice(EDU), "bio": bio,
        "interests": random.sample(INTERESTS, 4), "avatar": AVATARS[i % len(AVATARS)],
        "photos": [AVATARS[i % len(AVATARS)], AVATARS[(i+1) % len(AVATARS)]],
    })
    print("seeded", name)

# create some mutual likes -> matches
emails = list(tokens.keys())
def login(email):
    return requests.post(f"{BASE}/auth/login", json={"email":email,"password":"Demo@123"}).json()["token"]

if len(emails) >= 4:
    pairs = [(0,1),(2,3),(0,2),(4,5)]
    for a,b in pairs:
        ta = login(emails[a]); tb = login(emails[b])
        requests.post(f"{BASE}/like/{tokens[emails[b]]}", headers={"Authorization":f"Bearer {ta}"})
        requests.post(f"{BASE}/like/{tokens[emails[a]]}", headers={"Authorization":f"Bearer {tb}"})
    print("created matches")

print("DONE. Demo login: maya@demo.com / Demo@123")
