Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StorePlanRequest
100.00% covered (success)
100.00%
31 / 31
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 rules
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
1 / 1
1
 messages
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Requests\v2\Plan\Admin;
4
5use App\Http\Requests\v2\Parameter\Concerns\AuthorizesVengresoAdmin;
6use Illuminate\Foundation\Http\FormRequest;
7use Illuminate\Validation\Rule;
8
9/**
10 * Request for creating a new plan (admin).
11 *
12 * @property string $title The plan title
13 * @property string $identifier Unique plan identifier (e.g., "freemium", "starter")
14 * @property string|null $stripe_id Stripe price ID
15 * @property array|null $stripe_obj Stripe object data
16 * @property array|null $features Legacy features array
17 * @property string|null $hubspot_name HubSpot plan name
18 * @property bool $has_fly_learning Whether FlyLearning is available
19 * @property int $user_custom_prompts Custom prompts limit
20 * @property int $user_persona_available Number of personas allowed
21 * @property bool $can_disable_flygrammar Whether user can disable FlyGrammar
22 * @property int $flycut_deployment FlyCut deployment daily quota
23 * @property int $flygrammar_actions FlyGrammar actions daily quota
24 * @property int $prompts_per_day AI prompts daily quota
25 * @property int $regenerate_count AI regeneration limit
26 * @property array|null $flycuts_features Legacy FlyCuts features array
27 * @property string|null $stripe_product_id Stripe product ID
28 * @property bool $stripe_sync_enabled Whether to sync to Stripe
29 */
30class StorePlanRequest extends FormRequest
31{
32    use AuthorizesVengresoAdmin;
33
34    /**
35     * Get the validation rules that apply to the request.
36     *
37     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
38     */
39    public function rules(): array
40    {
41        return [
42            'title' => 'required|string|max:255',
43            'identifier' => [
44                'required',
45                'string',
46                'max:100',
47                'regex:/^[a-z][a-z0-9-]*$/',
48                Rule::unique('plans', 'identifier')->whereNull('pricing_version'),
49            ],
50            'stripe_id' => 'nullable|string|max:255',
51            'stripe_obj' => 'nullable|array',
52            'features' => 'nullable|array',
53            'hubspot_name' => 'nullable|string|max:255',
54            'has_fly_learning' => 'sometimes|boolean',
55            'user_custom_prompts' => 'sometimes|integer|min:-1',
56            'user_persona_available' => 'sometimes|integer|min:-1',
57            'can_disable_flygrammar' => 'sometimes|boolean',
58            'flycut_deployment' => 'sometimes|integer|min:-1',
59            'flygrammar_actions' => 'sometimes|integer|min:-1',
60            'prompts_per_day' => 'sometimes|integer|min:-1',
61            'regenerate_count' => 'sometimes|integer|min:-1',
62            'flycuts_features' => 'nullable|array',
63            'stripe_product_id' => 'nullable|string|max:255',
64            'stripe_sync_enabled' => 'sometimes|boolean',
65        ];
66    }
67
68    /**
69     * Get custom messages for validator errors.
70     *
71     * @return array<string, string>
72     */
73    public function messages(): array
74    {
75        return [
76            'title.required' => 'The plan title is required.',
77            'identifier.required' => 'The plan identifier is required.',
78            'identifier.regex' => 'The identifier must start with a letter and contain only lowercase letters, numbers, and hyphens.',
79            'identifier.unique' => 'A plan with this identifier already exists.',
80        ];
81    }
82}