<?php

declare(strict_types=1);

namespace App\Base;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * @return array<string, string[]>
     */
    public function rules(): array
    {
        return static::getRuleMap();
    }

    /**
     * @return array<string, string[]>
     */
    public static function getRuleMapForItemzz(bool $HasId = false): array
    {
        $RuleMap = [
            'Itemzz' => ['array', 'max:100', 'required'],
        ];
        if ($HasId) {
            $RuleMap['Itemzz.*.Id'] = ['integer', 'min:1', 'required'];
        }
        foreach (static::getRuleMap() as $Key => $Item) {
            $RuleMap["Itemzz.*.$Key"] = $Item;
        }

        return $RuleMap;
    }

    /**
     * @return array<string, string[]>
     */
    abstract public static function getRuleMap(): array;
}
