<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class BannerRequest extends FormRequest
{
    public function authorize(): bool { return true; }

    public function rules(): array
    {
        $isEdit = (bool) $this->input('id');

        return [
            'title'      => ['required', 'string', 'max:200'],
            'image'      => [$isEdit ? 'nullable' : 'required', 'image', 'mimes:jpg,jpeg,png,webp', 'max:3072'],
            'link_url'   => ['nullable', 'url', 'max:500'],
            'is_active'  => ['boolean'],
            'sort_order' => ['integer', 'min:0', 'max:9999'],
        ];
    }

    public function messages(): array
    {
        return [
            'title.required'  => 'Judul banner wajib diisi.',
            'image.required'  => 'Gambar banner wajib diunggah.',
            'image.image'     => 'File harus berupa gambar.',
            'image.max'       => 'Ukuran gambar maksimal 3MB.',
            'link_url.url'    => 'Format URL tidak valid.',
        ];
    }
}
