<?php

namespace Kylin\Licensing\Requests;

use Illuminate\Foundation\Http\FormRequest;

/**
 * 激活许可证请求
 */
class ActivateLicenseRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'license_key' => ['required', 'string', 'regex:/^KYL-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/'],
            'domain' => ['nullable', 'string', 'max:255'],
            'ip' => ['nullable', 'ip'],
        ];
    }

    public function messages(): array
    {
        return [
            'license_key.required' => '许可证密钥不能为空',
            'license_key.regex' => '许可证密钥格式无效，正确格式：KYL-XXXX-XXXX-XXXX-XXXX',
            'domain.max' => '域名长度不能超过255个字符',
            'ip.ip' => 'IP 地址格式无效',
        ];
    }
}
