<?php

namespace App\Http\Requests;

use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class ProfileUpdateRequest extends FormRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'name' => ['required', 'string', 'max:255'],
            'email' => [
                'required',
                'string',
                'lowercase',
                'email',
                'max:255',
                Rule::unique(User::class)->ignore($this->user()->id),
            ],
            'user_type' => ['required', 'in:individual,company'],
            'first_name' => ['required', 'string', 'max:255'],
            'last_name' => ['required', 'string', 'max:255'],
            'phone' => ['required', 'string', 'max:20'],

            // Câmpuri pentru companie - obligatorii doar dacă user_type = company
            'company_cui' => ['required_if:user_type,company', 'nullable', 'string', 'max:20'],
            'company_name' => ['required_if:user_type,company', 'nullable', 'string', 'max:255'],
            'company_reg_com' => ['nullable', 'string', 'max:50'],
            'company_address' => ['nullable', 'string', 'max:255'],
            'company_number' => ['nullable', 'string', 'max:20'],
            'company_city' => ['nullable', 'string', 'max:100'],
            'company_county' => ['nullable', 'string', 'max:100'],
            'company_postal_code' => ['nullable', 'string', 'max:10'],
            'company_country' => ['nullable', 'string', 'max:100'],
        ];
    }
}
