<?php
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

// 初始化租戶環境 (如果有的話)
tenancy()->initialize(\App\Modules\Core\Models\Tenant::where('id', 'koori')->first());

$v = App\Modules\Procurement\Models\Vendor::find(2);
$p = app(App\Modules\Procurement\Contracts\ProcurementServiceInterface::class);

echo "\n=== START TEST ===\n";
try {
    echo 'Check: ' . ($p->checkVendorHasProduct($v->id, 7) ? 'Yes' : 'No') . PHP_EOL;

    $p->attachProductToVendor($v->id, 7, 100);
    echo 'Check after attach: ' . ($p->checkVendorHasProduct($v->id, 7) ? 'Yes' : 'No') . PHP_EOL;
    echo 'Price: ' . $p->getVendorProductPrice($v->id, 7) . PHP_EOL;

    $p->updateVendorProductPrice($v->id, 7, 120);
    echo 'Price after update: ' . $p->getVendorProductPrice($v->id, 7) . PHP_EOL;

    $p->detachProductFromVendor($v->id, 7);
    echo 'Check after detach: ' . ($p->checkVendorHasProduct($v->id, 7) ? 'Yes' : 'No') . PHP_EOL;
} catch (\Exception $e) {
    echo "ERROR: " . $e->getMessage() . PHP_EOL;
}
echo "=== END TEST ===\n";
