<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UserAppsRequest extends FormRequest
{
    public function rules(): array
    {
        $rules = [
            'email' => 'sometimes|email',
            'phone' => 'sometimes|string|nullable',
        ];

        if (! $this->has('email')) {
            $rules['phone'] = 'required|string|max:20';
            $rules['email'] = 'nullable';
        }

        if (! $this->has('phone')) {
            $rules['email'] = 'required|email';
            $rules['phone'] = 'nullable';
        }

        return $rules;
    }
}
