<?php

use App\Domains\Workspace\Models\Workspace;
use App\Models\User;
use Database\Seeders\DevUserSeeder;
use Database\Seeders\PlanSeeder;

it('creates nexxo user with workspace after plan seed', function () {
    $this->seed(PlanSeeder::class);
    $this->seed(DevUserSeeder::class);

    $user = User::firstWhere('email', 'nexxo@nimuli.com');
    expect($user)->not->toBeNull();
    expect($user->default_workspace_id)->not->toBeNull();
    expect(Workspace::find($user->default_workspace_id))->not->toBeNull();
});

it('is idempotent — running twice does not duplicate', function () {
    $this->seed(PlanSeeder::class);
    $this->seed(DevUserSeeder::class);
    $this->seed(DevUserSeeder::class);

    expect(User::where('email', 'nexxo@nimuli.com')->count())->toBe(1);
    expect(Workspace::where('slug', 'nexxo')->count())->toBe(1);
});

it('is registered in DatabaseSeeder', function () {
    $source = file_get_contents(database_path('seeders/DatabaseSeeder.php'));
    expect($source)->toContain('DevUserSeeder::class');
});

it('PlanSeeder runs before DevUserSeeder in DatabaseSeeder', function () {
    $source = file_get_contents(database_path('seeders/DatabaseSeeder.php'));
    expect(strpos($source, 'PlanSeeder::class'))->toBeLessThan(strpos($source, 'DevUserSeeder::class'));
});
