<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

class ProductGroupStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return $this->user()->can('create', \App\Models\ProductGroup::class);
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'name' => 'required|string|max:255|unique:product_groups',
            'description' => 'nullable|string',
            'icon' => 'nullable|string',
            'order' => 'required|integer|min:0',
            'hidden' => 'nullable|boolean',
            'gateways' => 'nullable|string',
            'template' => 'nullable|string',
            'is_active' => 'boolean',
            // PRC-697 — pro-rata grup-seviyesi. Tri-state ('', '0', '1') controller'da normalize edilir.
            'proration_enabled' => 'nullable|in:,0,1',
            'billing_anchor_day' => 'nullable|integer|min:1|max:31',
        ];
    }

    /**
     * Get custom error messages for validator errors.
     */
    public function messages(): array
    {
        return [
            'name.required' => __('admin/product-groups.validation.name.required'),
            'name.unique' => __('admin/product-groups.validation.name.unique'),
            'order.required' => __('admin/product-groups.validation.order.required'),
            'order.integer' => __('admin/product-groups.validation.order.integer'),
            'order.min' => __('admin/product-groups.validation.order.min'),
        ];
    }
}
