<?php
/**
 * Form Request Class
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @version     STUB: 1.0.0
 * @generated   2026-03-23 09:15:00
 * @package     bplan-base/globals
 * @subpackage  FormRequests
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /Δ\
 */

namespace BplanBase\Globals\Http\Requests;


use BplanBase\Globals\Models\Tenant;
use BplanBase\Globals\Traits\FormRequestKeyPrefix;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * Form Request Class
 *
 * @version     1.0.0 / 2026-03-23
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 */
class StoreEntityTypeRequest extends FormRequest
{


/* +++ TRAITS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */


    use FormRequestKeyPrefix;


/* +++ CLASS CONSTANTS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT MEMBERS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * @var         null|string $_prefix
     */
    protected null|string $_prefix;


/* +++ CLASS MEMBERS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


/* +++ OBJECT METHODS +++ +++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * Determine if the user is authorized to make this request.
     *
     * @return      bool
     *
     * @version     1.0.0 / 2026-03-23
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function authorize(): bool
    {
        return true;

    } // authorize()


    /**
     * Get the validation rules that apply to the request
     *
     * @return      array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     *
     * @version     1.0.0 / 2026-03-23
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public function rules(): array
    {
        $tenantId = Tenant::current()->id;

        $rules = [
            'abstract'        => ['sometimes', 'required', 'boolean'],
            'active'          => ['sometimes', 'required', 'boolean'],
            'creatable'       => ['sometimes', 'required', 'boolean'],
            'delete_mode'     => ['sometimes', 'required', 'string'],
            'edit_type'       => ['sometimes', 'required', 'string', 'max:3'],
            'editable'        => ['sometimes', 'required', 'boolean'],
            'historize'       => ['sometimes', 'required', 'boolean'],
            'html_mask'       => ['nullable', 'string', 'max:500'],
            'identifier'      => ['required', 'string', 'max:65', Rule::unique('entity_types', 'identifier')->where('tenant_id', $tenantId)],
            'internal'        => ['sometimes', 'required', 'boolean'],
            'journalize'      => ['sometimes', 'required', 'boolean'],
            'labels'          => [],
            'main_type'       => ['required', 'string', 'max:32'],
            'master_id'       => ['nullable', 'integer'],
            'model_id'        => ['required', 'integer'],
            'module_id'       => ['required', 'integer'],
            'private'         => ['sometimes', 'required', 'boolean'],
            'require_release' => ['sometimes', 'required', 'boolean'],
            'resource_name'   => ['required', 'string', 'max:50'],
            'source_id'       => ['nullable', 'integer'],
            'sub_type'        => ['nullable', 'string', 'max:32'],
            'text_mask'       => ['nullable', 'string', 'max:255'],
            'visible'         => ['sometimes', 'required', 'boolean'],

        ];
        if ($this->_prefix === null) {
            return $rules;
        }
        return $this->_prependValidationRuleKeys($rules, $this->_prefix);

    } // rules()


/* +++ CLASS METHODS +++ ++++++++++++++++++++++++++++++++++++++++++++++++++++ */


    /**
     * Get the validation rules that apply to the request
     *
     * @param       int|string $id
     *
     * @param       null|string $prefix
     *
     * @return      array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     *
     * @version     1.0.0 / 2026-03-23
     * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
     * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
     */
    public static function getRules(null|string $prefix = null): array
    {
        $Instance = new static();

        $Instance->_prefix = $prefix;

        return $Instance->rules();

    } // getRules()


} // class StoreEntityTypeRequest extends FormRequest {}
