*/ class BackupSetFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'tenant_id' => Tenant::factory(), 'name' => fake()->words(3, true), 'created_by' => fake()->email(), 'status' => 'completed', 'item_count' => fake()->numberBetween(0, 100), 'completed_at' => now(), 'metadata' => [], ]; } public function recentCompleted(): static { return $this->state(fn (): array => [ 'status' => 'completed', 'completed_at' => now()->subMinutes(20), ]); } public function staleCompleted(): static { return $this->state(fn (): array => [ 'status' => 'completed', 'completed_at' => now()->subDays(2), 'item_count' => 1, ])->afterCreating(function ($backupSet): void { BackupItem::factory() ->for($backupSet->tenant) ->for($backupSet) ->create([ 'payload' => ['id' => 'stale-backup-item'], 'metadata' => [], 'assignments' => [], ]); }); } public function degradedCompleted(): static { return $this->state(fn (): array => [ 'status' => 'completed', 'completed_at' => now()->subMinutes(30), 'item_count' => 1, ])->afterCreating(function ($backupSet): void { BackupItem::factory() ->for($backupSet->tenant) ->for($backupSet) ->create([ 'payload' => [], 'metadata' => [ 'source' => 'metadata_only', 'assignments_fetch_failed' => true, ], 'assignments' => [], ]); }); } }