AgentThreadFactory.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Database\Factories;
  3. use App\Models\AgentThread;
  4. use App\Services\V3\AgentAccount;
  5. use Illuminate\Database\Eloquent\Factories\Factory;
  6. use Illuminate\Support\Str;
  7. /**
  8. * @extends Factory<AgentThread>
  9. */
  10. class AgentThreadFactory extends Factory
  11. {
  12. protected $model = AgentThread::class;
  13. /**
  14. * 默认是游客会话;登录用户的会话用 {@see self::forUser()}。
  15. *
  16. * @return array<string, mixed>
  17. */
  18. public function definition(): array
  19. {
  20. return [
  21. 'thread_id' => (string) Str::uuid(),
  22. 'account_type' => 'guest',
  23. 'account_id' => (string) Str::uuid(),
  24. 'title' => fake()->sentence(4),
  25. 'client' => 'mobile',
  26. 'last_run_at' => now(),
  27. ];
  28. }
  29. public function archived(): static
  30. {
  31. return $this->state(fn () => ['archived_at' => now()]);
  32. }
  33. /**
  34. * 登录用户的会话。
  35. */
  36. public function forUser(string $userUid): static
  37. {
  38. return $this->state(AgentAccount::user($userUid)->columns());
  39. }
  40. /**
  41. * 某台设备上游客的会话。
  42. */
  43. public function forGuest(string $deviceId): static
  44. {
  45. return $this->state(AgentAccount::guest($deviceId)->columns());
  46. }
  47. }