<?php

namespace Database\Factories;

use App\Models\EntraGroupSyncRun;
use App\Models\Tenant;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\EntraGroupSyncRun>
 */
class EntraGroupSyncRunFactory extends Factory
{
    protected $model = EntraGroupSyncRun::class;

    public function definition(): array
    {
        return [
            'tenant_id' => Tenant::factory(),
            'selection_key' => 'groups-v1:all',
            'slot_key' => null,
            'status' => EntraGroupSyncRun::STATUS_PENDING,
            'initiator_user_id' => User::factory(),
            'pages_fetched' => 0,
            'items_observed_count' => 0,
            'items_upserted_count' => 0,
            'error_count' => 0,
            'safety_stop_triggered' => false,
            'safety_stop_reason' => null,
            'error_code' => null,
            'error_category' => null,
            'error_summary' => null,
            'started_at' => null,
            'finished_at' => null,
        ];
    }

    public function scheduled(): static
    {
        return $this->state(fn (): array => [
            'initiator_user_id' => null,
        ]);
    }
}
