<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateMailProfileRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user() && $this->user()->can('update', $this->route('mail_profile'));
    }

    public function rules(): array
    {
        return [
            'name' => ['sometimes', 'required', 'string', 'max:190'],
            'host' => ['sometimes', 'required', 'string', 'max:190'],
            'port' => ['sometimes', 'required', 'integer', 'between:1,65535'],
            'encryption' => ['nullable', 'in:ssl,tls,starttls'],
            'username' => ['nullable', 'string', 'max:190'],
            'password' => ['nullable', 'string', 'max:512'],
            'from_address' => ['sometimes', 'required', 'email', 'max:190'],
            'from_name' => ['nullable', 'string', 'max:190'],
            'reply_to_address' => ['nullable', 'email', 'max:190'],
            'reply_to_name' => ['nullable', 'string', 'max:190'],
            'priority' => ['nullable', 'integer', 'between:0,65535'],
            'max_daily_quota' => ['nullable', 'integer', 'min:0'],
            'active' => ['nullable', 'boolean'],
            'signature' => ['nullable', 'array'],
            'signature.*' => ['nullable', 'string', 'max:1000'],
            'auto_mailer' => ['nullable', 'boolean'],
        ];
    }
}
