<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class MealPackageRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'sort_order' => 'nullable|integer|min:0',
            'title' => ['required', 'string', 'max:255'],
            'description' => ['nullable', 'string'],
            'price' => 'required_if:is_variant,false|numeric|nullable',
            'scope' => ['required', 'in:booking,all_rooms,room_category,room'],
            'tag' => ['nullable', 'string', 'max:100'],
            'is_icon' => ['nullable', 'boolean'],
            'icon_value' => ['nullable', 'string'],
            'is_variant' => ['required', 'boolean'],
            'is_allow_select_days' => ['required', 'boolean'],
            'is_published' => ['required', 'boolean'],
            'default_availability' => ['required', 'boolean'],

            'variants.*.id' => 'nullable',
            'variants.*.sort_order' => 'nullable|integer|min:0',
            'variants.*.title' => 'required_if:is_variant,true|string|max:255',
            'variants.*.price' => 'required_if:is_variant,true|numeric',
            'variants.*.is_published' => 'required_if:is_variant,true|boolean',
            'variants.*.default_availability' => 'required_if:is_variant,true|boolean',
            'variants.*.unit' => 'required_if:is_variant,true|integer',
            'variants.*.description' => 'nullable|string',
            'variants.*.is_icon' => 'nullable|boolean',
            'variants.*.icon_value' => 'nullable|string',

            'images' => ['nullable', 'array'],
            'images.*.id' => ['required', 'exists:images,id'],
            'images.*.role' => ['nullable', 'string'],
            'images.*.sort_order' => ['nullable', 'integer'],
        ];
    }
}
