<?php
// Script para criar usuário de teste
require_once __DIR__ . '/includes/config.php';

$pdo = getDB();

$name = 'Teste Login';
$email = 'teste@teste.com';
$phone = '11999999999';
$password = password_hash('123456', PASSWORD_DEFAULT);

// Criar para todas as lojas ativas
$stores = $pdo->query("SELECT id FROM stores WHERE is_active = 1")->fetchAll(PDO::FETCH_COLUMN);

foreach ($stores as $storeId) {
    // Verificar se já existe
    $stmt = $pdo->prepare("SELECT id FROM customers WHERE email = ? AND store_id = ?");
    $stmt->execute([$email, $storeId]);
    $existing = $stmt->fetch();

    if ($existing) {
        // Atualizar senha
        $stmt = $pdo->prepare("UPDATE customers SET password = ? WHERE id = ?");
        $stmt->execute([$password, $existing['id']]);
        echo "Senha atualizada para loja $storeId!\n";
    } else {
        // Inserir novo
        $stmt = $pdo->prepare("INSERT INTO customers (store_id, name, email, phone, password, is_active, created_at) VALUES (?, ?, ?, ?, ?, 1, NOW())");
        $stmt->execute([$storeId, $name, $email, $phone, $password]);
        echo "Cliente criado para loja $storeId!\n";
    }
}

echo "\nEmail: teste@teste.com\n";
echo "Senha: 123456\n";
