Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
StoreRolePlayPersonaTemplateRequest
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 authorize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 prepareForValidation
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 rules
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Requests\v2\RolePlay;
4
5use App\Http\Models\RolePlayPersonaTemplate;
6use App\Http\Services\RolePlay\ObjectionNormalizer;
7use Illuminate\Foundation\Http\FormRequest;
8
9/**
10 * Request for creating a new RolePlay Persona Template.
11 *
12 * Templates store the Persona Details + Product Details sections of a
13 * persona so they can be reused. They never store customer_profiles.
14 *
15 * @property string $name Template display name
16 * @property string|null $description Short description shown in the picker
17 * @property string $type Call type (cold-call|discovery-call)
18 * @property int $difficulty_level Difficulty level (1-5)
19 * @property array<int, string> $industry Target industries (1+ entries)
20 * @property array<int, string>|null $target_job_titles Target buyer job titles
21 * @property array<int, string> $company_sizes Targeted company sizes (subset of small|medium|large)
22 * @property array<int, string>|null $key_features Product key features
23 * @property string|null $product_description Product description
24 * @property array<int, array{category: string, options: array<int, string>}>|null $objections Objection blocks (preserved on hydrate)
25 * @property string $visibility personal|company (company requires Global Admin role)
26 */
27class StoreRolePlayPersonaTemplateRequest extends FormRequest
28{
29    /**
30     * Determine if the user is authorized to make this request.
31     *
32     * Visibility-level write authorization is enforced in the service layer
33     * (so the controller stays thin and the rule lives next to the model).
34     */
35    public function authorize(): bool
36    {
37        return $this->user() !== null;
38    }
39
40    /**
41     * Normalize legacy-shape `objections` (string options or duplicate
42     * categories) into the canonical {text, company_sizes} shape BEFORE
43     * validation rules fire.
44     */
45    protected function prepareForValidation(): void
46    {
47        if ($this->has('objections')) {
48            $this->merge([
49                'objections' => ObjectionNormalizer::normalize($this->input('objections')),
50            ]);
51        }
52    }
53
54    /**
55     * Get the validation rules that apply to the request.
56     *
57     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
58     */
59    public function rules(): array
60    {
61        return RolePlayPersonaTemplate::getRules();
62    }
63}