<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Route;

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

    public function rules(): array
    {
        $route = Route::currentRouteName();
        $rules = [];

        $routeRules = [
            'brand.index' => [
                'fk_site' => ['required', 'integer', 'exists:sy_sites,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id']
            ],
            'brand.store' => [
                'fk_site' => ['required', 'integer', 'exists:sy_sites,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
                'brandname' => ['required', 'string', 'min:2', 'max:35'],
            ],
            'brand.update' => [
                'id' => ['required', 'integer', 'exists:ct_brands,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
                'brandname' => ['required', 'string', 'min:2', 'max:35'],
            ],
            'brand.destroy' => [
                'id' => ['required', 'integer', 'exists:ct_brands,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
            ],
            'brand.changeStatus' => [
                'id' => ['required', 'integer', 'exists:ct_brands,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
                'available' => ['required', 'boolean'],
            ],
            'brand.changeVisibility' => [
                'id' => ['required', 'integer', 'exists:ct_brands,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
                'visible' => ['required', 'boolean'],
            ],
            'brand.list' => [
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
            ],
            'brand.show' => [
                'id' => ['required', 'integer', 'exists:ct_brands,id'],
                'fk_office' => ['required', 'integer', 'exists:sy_offices,id'],
            ]
        ];

        return array_merge($rules, $routeRules[$route]);
    }
}
