<?php



namespace App\Http\Requests\Profile;



use Illuminate\Foundation\Http\FormRequest;

use Illuminate\Validation\Rule;



class UploadProfileImageRequest extends FormRequest

{

    public function authorize(): bool

    {

        $profile = $this->user()?->playerProfile;



        return $profile !== null && $this->user()->can('update', $profile);

    }



    public function rules(): array

    {

        $type = $this->input('type', 'avatar');

        $maxKb = (int) config("esports.uploads.{$type}.max_kb", 2048);



        return [

            'type' => ['required', Rule::in(['avatar', 'cover'])],

            'image' => ['required', 'file', 'image', 'mimes:jpg,jpeg,png,webp', 'max:'.$maxKb],

        ];

    }

}

