<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        $pageId = $this->route('cm')?->id ?? $this->route('cm');

        return [
            'title' => ['required', 'string', 'max:200'],
            'slug' => ['required', 'string', 'max:200', "unique:pages,slug,{$pageId}"],
            'content' => ['nullable', 'string'],
            'type' => ['required', 'in:landing,static,blog'],
            'meta_title' => ['nullable', 'string', 'max:200'],
            'meta_description' => ['nullable', 'string', 'max:500'],
            'meta_image' => ['nullable', 'string', 'max:500'],
            'is_published' => ['sometimes', 'boolean'],
        ];
    }
}
