trypost/app/Http/Requests/App/Ai/StartPostCreationRequest.php
Paulo Castellano 2c2ab69e68 Merge main + finalize AI brand-colors toggle
Resolves the AiPostWizard conflict and completes the feature:
- i18n parity: brand_colors_label + brand_colors_description in all 15 locales
  (was en/es/pt-BR only, which broke LocalizationParityTest).
- Reworked the two-button toggle into a Switch with an explanatory description
  (matches the settings Switch/card pattern).
- Only shown for templates that honor the flag: added appliesBrandVisuals() to
  the AiContentTemplate contract (ImageCard=true, tweet cards=false), exposed as
  applies_brand_visuals in the create-page DTO, and gated the toggle on it — so
  it no longer appears (as a no-op) for tweet-card styles.
- Tests: TemplateContractTest covers appliesBrandVisuals for all templates.
2026-07-18 15:12:26 -03:00

55 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Requests\App\Ai;
use App\Enums\Ai\ContentStyle;
use App\Enums\PostPlatform\ContentType;
use App\Support\AiPromptRules;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Validator;
class StartPostCreationRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
/**
* @return array<string, mixed>
*/
public function rules(): array
{
$allowedFormats = array_map(fn (ContentType $t) => $t->value, ContentType::aiSupported());
$allowedFormats[] = ContentType::CAROUSEL_FORMAT;
return [
'format' => [
'required',
'string',
Rule::in($allowedFormats),
],
'social_account_id' => ['nullable', 'uuid'],
'image_count' => ['nullable', 'integer', 'min:0', 'max:10'],
'prompt' => AiPromptRules::wizardPromptRule(),
'date' => ['nullable', 'date_format:Y-m-d'],
'template' => ['sometimes', 'string', Rule::enum(ContentStyle::class)],
'apply_brand_visuals' => ['sometimes', 'boolean'],
];
}
public function withValidator(Validator $validator): void
{
$validator->after(function (Validator $validator): void {
$style = ContentStyle::tryFrom((string) $this->input('template', ContentStyle::default()->value))
?? ContentStyle::default();
if ($style->needsAccount() && blank($this->input('social_account_id'))) {
$validator->errors()->add('social_account_id', trans('validation.required', ['attribute' => 'social account']));
}
});
}
}