<?php

namespace App\Http\Requests\Agency;

use Illuminate\Foundation\Http\FormRequest;

class UpdateThemeSettingsRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->hasAgency()
            && ($this->user()->isAgencyOwner() || $this->user()->hasRole(['agency-manager']));
    }

    public function rules(): array
    {
        return [
            'colors' => 'nullable|array',
            'colors.primary' => 'nullable|string|regex:/^#[0-9A-F]{6}$/i',
            'colors.secondary' => 'nullable|string|regex:/^#[0-9A-F]{6}$/i',
            'colors.accent' => 'nullable|string|regex:/^#[0-9A-F]{6}$/i',
            'colors.text' => 'nullable|string|regex:/^#[0-9A-F]{6}$/i',
            'colors.background' => 'nullable|string|regex:/^#[0-9A-F]{6}$/i',
            'colors.muted' => 'nullable|string|regex:/^#[0-9A-F]{6}$/i',

            'typography' => 'nullable|array',
            'typography.font_family' => 'nullable|string|max:100',
            'typography.heading_font' => 'nullable|string|max:100',
            'typography.font_size_base' => 'nullable|string|max:20',
            'typography.heading_weight' => 'nullable|string|max:20',
            'typography.body_weight' => 'nullable|string|max:20',

            'layout' => 'nullable|array',
            'layout.container_width' => 'nullable|string|max:20',
            'layout.border_radius' => 'nullable|string|max:20',
            'layout.spacing_unit' => 'nullable|string|max:20',
            'layout.header_height' => 'nullable|string|max:20',
            'layout.footer_style' => 'nullable|string|max:50',

            'effects' => 'nullable|array',
            'effects.shadow_sm' => 'nullable|string|max:100',
            'effects.shadow_md' => 'nullable|string|max:100',
            'effects.shadow_lg' => 'nullable|string|max:100',
            'effects.transition' => 'nullable|string|max:20',
            'effects.hover_scale' => 'nullable|string|max:20',

            'components' => 'nullable|array',
            'components.button_style' => 'nullable|string|max:50',
            'components.card_style' => 'nullable|string|max:50',
            'components.input_style' => 'nullable|string|max:50',
            'components.image_aspect' => 'nullable|string|max:20',
        ];
    }

    public function messages(): array
    {
        return [
            'colors.*.regex' => 'Geçerli bir HEX renk kodu giriniz (örn: #3B82F6)',
            'typography.*.max' => 'Değer çok uzun',
            'layout.*.max' => 'Değer çok uzun',
            'effects.*.max' => 'Değer çok uzun',
            'components.*.max' => 'Değer çok uzun',
        ];
    }
}
