Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
RolePlayPersonaTemplate
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 user
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRules
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Models;
4
5use App\Http\Models\Auth\User;
6use Illuminate\Database\Eloquent\Relations\BelongsTo;
7use Illuminate\Validation\Rule;
8
9/**
10 * RolePlay Persona Template.
11 *
12 * Reusable persona blueprint that captures the Persona Details + Product
13 * Details sections of a {@see RolePlayProjects} (but NOT customer_profiles
14 * or session history). Users hydrate a new persona from a template, then
15 * regenerate fresh ICPs against the template's product context.
16 *
17 * Visibility:
18 *  - "personal": owner-only, scoped by user_id
19 *  - "company": shared with all users in the same company; only company
20 *    Global Admins can create/edit/delete these
21 *
22 * @property string $name
23 * @property string|null $description
24 * @property string $type
25 * @property string|null $difficulty_level
26 * @property array|null $industry
27 * @property array|null $target_job_titles
28 * @property array|null $company_sizes
29 * @property array|null $key_features
30 * @property string|null $product_description
31 * @property array|null $objections
32 * @property string $visibility
33 * @property string|null $user_id
34 * @property string|null $company_id
35 */
36class RolePlayPersonaTemplate extends Moloquent
37{
38    public const VISIBILITY_PERSONAL = 'personal';
39
40    public const VISIBILITY_COMPANY = 'company';
41
42    public const VISIBILITIES = [self::VISIBILITY_PERSONAL, self::VISIBILITY_COMPANY];
43
44    protected $table = 'roleplay_persona_templates';
45
46    protected $fillable = [
47        'name',
48        'description',
49        'type',
50        'difficulty_level',
51        'industry',
52        'target_job_titles',
53        'company_sizes',
54        'key_features',
55        'product_description',
56        'objections',
57        'visibility',
58        'user_id',
59        'company_id',
60        'created_at',
61        'updated_at',
62    ];
63
64    /**
65     * Owner of the template (creator).
66     */
67    public function user(): BelongsTo
68    {
69        return $this->belongsTo(User::class, 'user_id');
70    }
71
72    /**
73     * Validation rules shared by Store and Update form requests.
74     *
75     * @return array<string, mixed>
76     */
77    public static function getRules(): array
78    {
79        return [
80            'name' => 'required|string|max:255',
81            'description' => 'nullable|string|max:1024',
82            'type' => ['required', 'string', Rule::in([RolePlayProjects::$COLD_CALL, RolePlayProjects::$DISCOVERY_CALL])],
83            'difficulty_level' => 'required|integer|min:1|max:5',
84            'industry' => 'required|array|min:1',
85            'industry.*' => 'string|max:255',
86            'target_job_titles' => 'nullable|array',
87            'target_job_titles.*' => 'string|max:255',
88            'company_sizes' => 'required|array|min:1',
89            'company_sizes.*' => ['required', 'string', Rule::in(RolePlayProjects::COMPANY_SIZE_KEYS)],
90            'key_features' => 'nullable|array',
91            'key_features.*' => 'string|max:255',
92            'product_description' => 'nullable|string',
93            'objections' => 'required|array|min:1',
94            'objections.*.category' => 'required|string',
95            'objections.*.options' => 'required|array|min:1',
96            'objections.*.options.*' => 'required|array',
97            'objections.*.options.*.text' => 'required|string|max:2000',
98            'objections.*.options.*.company_sizes' => ['required', 'array', 'min:1'],
99            'objections.*.options.*.company_sizes.*' => ['required', 'string', Rule::in(RolePlayProjects::COMPANY_SIZE_KEYS)],
100            'visibility' => ['required', 'string', Rule::in(self::VISIBILITIES)],
101        ];
102    }
103}