<?php

namespace App\Http\Requests\Admin;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;

class UpdateMobileSettingRequest 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, ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            // General
            'app_name' => ['nullable', 'string', 'max:50'],
            'app_version' => ['nullable', 'string', 'max:20'],

            // Theme & Colors
            'primary_color' => ['nullable', 'string', 'regex:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/'],
            'secondary_color' => ['nullable', 'string', 'regex:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/'],
            'dark_background' => ['nullable', 'string', 'regex:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/'],
            'splash_bg_color' => ['nullable', 'string', 'regex:/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/'],
            'border_radius' => ['nullable', 'string', 'max:10'],

            // Dashboard Grid
            'welcome_text' => ['nullable', 'string', 'max:100'],
            'label_grid_1' => ['nullable', 'string', 'max:30'],
            'label_grid_2' => ['nullable', 'string', 'max:30'],
            'label_grid_3' => ['nullable', 'string', 'max:30'],
            'label_grid_4' => ['nullable', 'string', 'max:30'],
            'icon_grid_1' => ['nullable', 'string', 'max:50'],
            'icon_grid_2' => ['nullable', 'string', 'max:50'],
            'icon_grid_3' => ['nullable', 'string', 'max:50'],
            'icon_grid_4' => ['nullable', 'string', 'max:50'],
            'color_grid_1' => ['nullable', 'string'],
            'color_grid_2' => ['nullable', 'string'],
            'color_grid_3' => ['nullable', 'string'],
            'color_grid_4' => ['nullable', 'string'],

            // Assets (Files)
            'logo_light_url' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg,webp', 'max:5120'],
            'logo_dark_url' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg,webp', 'max:5120'],
            'splash_image_url' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg,webp', 'max:5120'],
            'maintenance_image' => ['nullable', 'image', 'mimes:jpeg,png,jpg,gif,svg,webp', 'max:5120'],

            // Support & Navigation
            'support_email' => ['nullable', 'email'],
            'support_whatsapp' => ['nullable', 'string', 'max:20'],
            'emergency_phone' => ['nullable', 'string', 'max:20'],
            'tab_home' => ['nullable', 'string', 'max:20'],

            // Flags & Announcements
            'kill_switch_active' => ['nullable', 'boolean'],
            'kill_switch_message' => ['nullable', 'string'],
            'announcement_enabled' => ['nullable', 'boolean'],
            'announcement_text' => ['nullable', 'string'],
            'announcement_type' => ['nullable', 'string', 'in:info,warning,danger'],

            // System & Engagement
            'min_app_version' => ['nullable', 'string', 'max:20'],
            'onboarding_version' => ['nullable', 'string', 'max:20'],
            'maintenance_start_at' => ['nullable', 'string', 'nullable'],
            'maintenance_end_at' => ['nullable', 'string', 'nullable'],
            'review_prompt_enabled' => ['nullable', 'boolean'],
            'min_actions_before_review' => ['nullable', 'integer', 'min:0'],

            // Catch-all for other dynamic settings
            '*' => ['nullable'],
        ];
    }
}
