import requests

API_URL = "http://127.0.0.1:8000"


# Lista de mesas con abreviatura, nombre, pos_x, pos_y (coordenadas de cuadrícula)
TABLES = [
    ("FE", "Fora Esquerra", 0, 0),
    ("F2E", "Fora 2a Esquerra", 1, 0),
    ("FM", "Fora Mig", 3, 0),
    ("F2D", "Fora 2a Dreta", 5, 0),
    ("FD", "Fora Dreta", 6, 0),
    ("PE", "Primera Esquerra", 0, 1),
    ("2E", "Segona Esquerra", 1, 1),
    ("MIG", "Mig", 3, 1),
    ("2D", "Segona Dreta", 5, 1),
    ("PD", "Punta Dreta", 6, 1),
    ("TV1", "Televisió 1", 0, 2),
    ("BE", "Banc Esquerra", 2, 2),
    ("B", "Banc", 3, 2),
    ("BD", "Banc Dreta", 4, 2),
    ("DTV2", "Devant TV2", 5, 2),
    ("ENT", "Entrada", 6, 2),
    ("E3", "Esquerra 3", 0, 3),
    ("E2", "Esquerra 2", 1, 3),
    ("E1", "Esquerra 1", 2, 3),
    ("B3", "Banc 3", 4, 3),
    ("STV2", "Sota TV2", 5, 3),
    ("D3", "Devant 3", 0, 4),
    ("D2", "Devant 2", 1, 4),
    ("D1", "Devant 1", 2, 4),
    ("B2", "Banc 2", 4, 4),
    ("BIL", "Billar", 6, 4),
    ("B1", "Banc 1", 4, 5),
    ("VIP", "VIP", 6, 5)
]

def create_tables():
    for i, (abbr, name, pos_x, pos_y) in enumerate(TABLES, start=1):
        data = {
            "number": i,
            "abbreviation": abbr,
            "name": name,
            "pos_x": pos_x,
            "pos_y": pos_y
        }
        resp = requests.post(f"{API_URL}/tables/", json=data)
        if resp.status_code in (200, 201):
            print(f"Mesa creada: {abbr} ({name}) (número {i}) pos({pos_x},{pos_y})")
        elif resp.status_code == 400 and "already exists" in resp.text:
            print(f"Mesa ya existía: {abbr}")
        else:
            print(f"Error creando mesa {abbr}: {resp.status_code} {resp.text}")

if __name__ == "__main__":
    create_tables()
