<?php

namespace App\Http\Requests\Admin\System\Setting;

use App\Enums\Permission;
use App\Rules\PhoneNumber;
use Illuminate\Foundation\Http\FormRequest;

class SystemRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()?->can(Permission::SETTINGS_UPDATE->value) ?? false;
    }

    /**
     * @return array<string, mixed>
     */
    public function rules(): array
    {
        return [
            'app_name' => ['required', 'string', 'max:100'],
            'about_app' => ['required', 'string'],
            'email' => ['required', 'email', 'max:100'],
            'phone' => ['required', 'string', 'max:20', new PhoneNumber],
            'address' => ['required', 'string'],
            'logo' => ['nullable', 'image', 'max:2048'],
            'favicon' => ['nullable', 'image', 'max:1024'],
            'login_cover' => ['nullable', 'image', 'max:5120'],
        ];
    }

    /**
     * @return array<string, string>
     */
    public function attributes(): array
    {
        return [
            'app_name' => 'nama aplikasi',
            'about_app' => 'tentang aplikasi',
            'email' => 'email',
            'phone' => 'nomor telepon',
            'address' => 'alamat',
            'logo' => 'logo',
            'favicon' => 'favicon',
            'login_cover' => 'cover login',
        ];
    }
}
