<?php

namespace App\Http\Requests\Customer;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        return [
            'tenant_id' => ['nullable', 'integer', 'exists:tenants,id'],
            'user_id' => ['nullable', 'integer', 'exists:users,id'],
            'customer_code' => ['nullable', 'string', 'max:100'],
            'name' => ['required', 'string', 'max:255'],
            'identity_number' => ['nullable', 'string', 'max:100'],
            'email' => ['nullable', 'email', 'max:255'],
            'whatsapp_number' => ['nullable', 'string', 'max:50'],
            'installation_address' => ['nullable', 'string'],
            'provinsi_id' => ['nullable', 'integer', 'exists:wilayah_provinsi,id'],
            'kabupaten_id' => ['nullable', 'integer', 'exists:wilayah_kabupaten,id'],
            'kecamatan_id' => ['nullable', 'integer', 'exists:wilayah_kecamatan,id'],
            'desa_id' => ['nullable', 'integer', 'exists:wilayah_desa,id'],
            'latitude' => ['nullable', 'numeric', 'between:-90,90'],
            'longitude' => ['nullable', 'numeric', 'between:-180,180'],
            'package_profile_id' => ['nullable', 'integer', 'exists:nas_package_profiles,id'],
            'nas_mikrotik_id' => ['nullable', 'integer', 'exists:nas_mikrotiks,id'],
            'billing_profile_id' => ['nullable', 'integer', 'min:1'],
            'topology_id' => ['nullable', 'integer', 'min:1'],
            'external_username' => ['nullable', 'string', 'max:255'],
            'source' => ['nullable', Rule::in(['manual', 'mikrotik', 'radius'])],
            'order_stage' => ['nullable', Rule::in(['registration', 'data_completion', 'ready_activation', 'activation_failed'])],
            'notes' => ['nullable', 'string'],
            'images' => ['nullable', 'array', 'max:20'],
            'images.*.stored_file_id' => ['required', 'integer', 'exists:stored_files,id'],
            'images.*.category' => ['required', Rule::in(['house', 'installation', 'modem', 'odp', 'cable', 'identity', 'other'])],
            'images.*.caption' => ['nullable', 'string', 'max:255'],
            'images.*.is_cover' => ['nullable', 'boolean'],
            'images.*.sort_order' => ['nullable', 'integer', 'min:0', 'max:1000'],
        ];
    }
}
