<?php
namespace App\Http\Requests;use App\Services\ProjectUrlNormalizer;use Illuminate\Foundation\Http\FormRequest;use Illuminate\Validation\ValidationException;
class StoreCompetitorRequest extends FormRequest{public function authorize():bool{return$this->user()!==null;}protected function prepareForValidation():void{try{$n=app(ProjectUrlNormalizer::class)->normalize((string)$this->input('domain'));$this->merge(['normalized_domain'=>$n->domain,'domain'=>$n->domain,'name'=>trim((string)$this->input('name'))?:$n->domain]);}catch(\InvalidArgumentException$e){throw ValidationException::withMessages(['domain'=>__('competitors.invalid_domain')]);}}public function rules():array{return['name'=>['required','string','max:150'],'domain'=>['required','string','max:253'],'normalized_domain'=>['required','string','max:253']];}}
