Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
StoreCompanyProjectRequest
100.00% covered (success)
100.00%
16 / 16
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%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Requests\CompanyRolePlay;
4
5use App\Http\Models\RolePlayProjects;
6use App\Http\Services\RolePlay\ObjectionNormalizer;
7use Illuminate\Foundation\Http\FormRequest;
8use Illuminate\Validation\Rule;
9
10/**
11 * Request validation for creating a new company roleplay project.
12 *
13 * @property string $name The project name (required, max 255 chars)
14 * @property string $type The call type ('cold-call' or 'discovery-call')
15 * @property string|null $description Optional project description
16 * @property string $industry The target industry
17 * @property array<string> $target_job_titles Array of targeted job titles (at least 1)
18 * @property array<string>|null $key_features Optional array of key product/service features
19 * @property string|null $product_description Optional product description
20 * @property int $difficulty_level Difficulty level (1-5)
21 * @property array<array{id: int, company_name: string, company_size: string, budget: string, decision_making: string, urgency_level: string, openess_to_new_solutions: string, communication_style: string, pain_points: string, current_solution: string, personality: string}> $customer_profiles Array of customer profile objects (at least 1)
22 * @property array<array{name: string, is_default: bool, weight: int, criteria: array}> $scorecard_config Array of scorecard config objects (at least 1)
23 * @property array<array{category: string, options: array<string>}> $objections Array of objection objects (at least 1)
24 * @property bool|null $allow_user_customization Whether users can customize when cloning (default: true)
25 * @property array<string>|null $assigned_groups Optional array of group IDs (empty means all users)
26 * @property string|null $status Project status ('active', 'inactive', 'archived'; default: 'active')
27 */
28class StoreCompanyProjectRequest extends FormRequest
29{
30    /**
31     * Determine if the user is authorized to make this request.
32     *
33     * Authorization is handled in the controller by checking company_id.
34     */
35    public function authorize(): bool
36    {
37        return true;
38    }
39
40    /**
41     * Normalize legacy-shape `objections` payloads into the canonical
42     * {text, company_sizes} shape BEFORE validation rules fire.
43     */
44    protected function prepareForValidation(): void
45    {
46        if ($this->has('objections')) {
47            $this->merge([
48                'objections' => ObjectionNormalizer::normalize($this->input('objections')),
49            ]);
50        }
51    }
52
53    /**
54     * Get the validation rules that apply to the request.
55     *
56     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
57     */
58    public function rules(): array
59    {
60        return array_merge(RolePlayProjects::getRules(), [
61            'product_description' => 'nullable|string',
62            'allow_user_customization' => 'sometimes|boolean',
63            'allow_clone' => 'sometimes|boolean',
64            'allow_direct_calls' => 'sometimes|boolean',
65            'assigned_groups' => 'sometimes|array',
66            'assigned_groups.*' => 'string',
67            'assigned_users' => 'sometimes|array',
68            'assigned_users.*' => 'string',
69            'status' => ['sometimes', 'string', Rule::in(['active', 'inactive', 'archived'])],
70        ]);
71    }
72}