Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UpdateCompanyProjectRequest
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
2 / 2
6
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
 rules
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
1 / 1
5
1<?php
2
3namespace App\Http\Requests\CompanyRolePlay;
4
5use App\Http\Models\RolePlayProjects;
6use Illuminate\Foundation\Http\FormRequest;
7use Illuminate\Validation\Rule;
8
9/**
10 * Request validation for updating an existing company roleplay project.
11 *
12 * All fields are optional for partial updates.
13 *
14 * @property string|null $name The project name (max 255 chars)
15 * @property string|null $type The call type ('cold-call' or 'discovery-call')
16 * @property string|null $description Optional project description
17 * @property string|null $industry The target industry
18 * @property array<string>|null $target_job_titles Array of targeted job titles
19 * @property array<string>|null $key_features Array of key product/service features
20 * @property string|null $product_description Optional product description
21 * @property int|null $difficulty_level Difficulty level (1-5)
22 * @property array|null $customer_profiles Array of customer profile objects
23 * @property array|null $scorecard_config Array of scorecard config objects
24 * @property array|null $objections Array of objection objects
25 * @property bool|null $allow_user_customization Whether users can customize when cloning
26 * @property array<string>|null $assigned_groups Array of group IDs (empty means all users)
27 * @property string|null $status Project status ('active', 'inactive', 'archived', 'draft')
28 */
29class UpdateCompanyProjectRequest extends FormRequest
30{
31    /**
32     * Determine if the user is authorized to make this request.
33     *
34     * Authorization is handled in the controller by checking company_id.
35     */
36    public function authorize(): bool
37    {
38        return true;
39    }
40
41    /**
42     * Get the validation rules that apply to the request.
43     *
44     * Makes all base rules optional by prepending 'sometimes' to required rules.
45     *
46     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
47     */
48    public function rules(): array
49    {
50        $baseRules = RolePlayProjects::getRules();
51
52        // Make all rules optional for partial updates
53        $rules = [];
54        foreach ($baseRules as $key => $rule) {
55            if (is_string($rule)) {
56                $rule = str_replace('required|', 'sometimes|', $rule);
57                $rule = str_replace('required', 'sometimes', $rule);
58            } elseif (is_array($rule)) {
59                $rule = array_map(function ($r) {
60                    return $r === 'required' ? 'sometimes' : $r;
61                }, $rule);
62            }
63            $rules[$key] = $rule;
64        }
65
66        return array_merge($rules, [
67            'product_description' => 'nullable|string',
68            'allow_user_customization' => 'sometimes|boolean',
69            'assigned_groups' => 'sometimes|array',
70            'assigned_groups.*' => 'string',
71            'status' => ['sometimes', 'string', Rule::in(['active', 'inactive', 'archived', 'draft'])],
72        ]);
73    }
74}