1+ <?php
2+
3+ namespace Database \Factories ;
4+
5+ use App \Models \ConversationSession ;
6+ use Illuminate \Database \Eloquent \Factories \Factory ;
7+
8+ /**
9+ * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ConversationSession>
10+ */
11+ class ConversationSessionFactory extends Factory
12+ {
13+ protected $ model = ConversationSession::class;
14+
15+ /**
16+ * Define the model's default state.
17+ *
18+ * @return array<string, mixed>
19+ */
20+ public function definition (): array
21+ {
22+ $ startedAt = $ this ->faker ->dateTimeBetween ('-1 month ' , 'now ' );
23+ $ endedAt = $ this ->faker ->optional (0.7 )->dateTimeBetween ($ startedAt , 'now ' );
24+
25+ return [
26+ 'user_id ' => null , // Single-user desktop app
27+ 'title ' => $ this ->faker ->sentence (4 ),
28+ 'customer_name ' => $ this ->faker ->name (),
29+ 'customer_company ' => $ this ->faker ->company (),
30+ 'started_at ' => $ startedAt ,
31+ 'ended_at ' => $ endedAt ,
32+ 'duration_seconds ' => $ endedAt ? $ this ->faker ->numberBetween (60 , 3600 ) : 0 ,
33+ 'template_used ' => $ this ->faker ->randomElement (['sales_call ' , 'discovery ' , 'demo ' , 'follow_up ' , null ]),
34+ 'final_intent ' => $ endedAt ? $ this ->faker ->randomElement (['high ' , 'medium ' , 'low ' , null ]) : null ,
35+ 'final_buying_stage ' => $ endedAt ? $ this ->faker ->randomElement (['awareness ' , 'consideration ' , 'evaluation ' , 'purchase ' , null ]) : null ,
36+ 'final_engagement_level ' => $ endedAt ? $ this ->faker ->numberBetween (0 , 100 ) : 50 ,
37+ 'final_sentiment ' => $ endedAt ? $ this ->faker ->randomElement (['positive ' , 'neutral ' , 'negative ' , null ]) : null ,
38+ 'total_transcripts ' => $ this ->faker ->numberBetween (0 , 100 ),
39+ 'total_insights ' => $ this ->faker ->numberBetween (0 , 20 ),
40+ 'total_topics ' => $ this ->faker ->numberBetween (0 , 10 ),
41+ 'total_commitments ' => $ this ->faker ->numberBetween (0 , 5 ),
42+ 'total_action_items ' => $ this ->faker ->numberBetween (0 , 8 ),
43+ 'ai_summary ' => $ endedAt ? $ this ->faker ->optional (0.8 )->paragraph () : null ,
44+ 'user_notes ' => $ this ->faker ->optional (0.3 )->paragraph (),
45+ ];
46+ }
47+
48+ /**
49+ * Indicate that the session is ongoing (not ended).
50+ */
51+ public function ongoing (): static
52+ {
53+ return $ this ->state (fn (array $ attributes ) => [
54+ 'ended_at ' => null ,
55+ 'duration_seconds ' => 0 ,
56+ 'final_intent ' => null ,
57+ 'final_buying_stage ' => null ,
58+ 'final_engagement_level ' => 50 ,
59+ 'final_sentiment ' => null ,
60+ 'ai_summary ' => null ,
61+ ]);
62+ }
63+
64+ /**
65+ * Indicate that the session is completed.
66+ */
67+ public function completed (): static
68+ {
69+ return $ this ->state (function (array $ attributes ) {
70+ $ startedAt = $ attributes ['started_at ' ] ?? now ()->subHour ();
71+ $ endedAt = now ();
72+
73+ return [
74+ 'ended_at ' => $ endedAt ,
75+ 'duration_seconds ' => $ endedAt ->diffInSeconds ($ startedAt ),
76+ 'final_intent ' => $ this ->faker ->randomElement (['high ' , 'medium ' , 'low ' ]),
77+ 'final_buying_stage ' => $ this ->faker ->randomElement (['awareness ' , 'consideration ' , 'evaluation ' , 'purchase ' ]),
78+ 'final_engagement_level ' => $ this ->faker ->numberBetween (40 , 100 ),
79+ 'final_sentiment ' => $ this ->faker ->randomElement (['positive ' , 'neutral ' , 'negative ' ]),
80+ 'ai_summary ' => $ this ->faker ->paragraph (),
81+ ];
82+ });
83+ }
84+ }
0 commit comments