<?php

namespace App\Http\Requests\Admin;

use Illuminate\Foundation\Http\FormRequest;

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

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'product_id' => 'required|integer|exists:products,id',
            'currency_id' => 'required|integer|exists:currencies,id',
            'periods' => 'required|array',
            'periods.1' => 'nullable|numeric|min:0|max:999999.99',
            'periods.3' => 'nullable|numeric|min:0|max:999999.99',
            'periods.6' => 'nullable|numeric|min:0|max:999999.99',
            'periods.12' => 'nullable|numeric|min:0|max:999999.99',
            'periods.24' => 'nullable|numeric|min:0|max:999999.99',
            'periods.36' => 'nullable|numeric|min:0|max:999999.99',
            'is_active' => 'boolean',
            'metadata' => 'nullable|array',
        ];
    }

    public function messages(): array
    {
        return [
            'product_id.required' => __('admin/validation.service_cost_product_id_required'),
            'product_id.exists'   => __('admin/validation.service_cost_product_id_exists'),
            'currency_id.required' => __('admin/validation.service_cost_currency_required'),
            'currency_id.exists'   => __('admin/validation.service_cost_currency_in'),
            'periods.required'    => __('admin/validation.service_cost_periods_required'),
            'periods.array'       => __('admin/validation.service_cost.periods_array'),
            'periods.*.numeric'   => __('admin/validation.service_cost_periods_numeric'),
            'periods.*.min'       => __('admin/validation.service_cost_periods_min'),
            'periods.*.max'       => __('admin/validation.service_cost_periods_max'),
            'metadata.array'      => __('admin/validation.service_cost.metadata_array'),
        ];
    }

    public function attributes(): array
    {
        return [
            'product_id'  => 'ürün',
            'currency_id' => 'para birimi',
            'periods'     => 'dönem fiyatları',
            'is_active'   => 'aktiflik durumu',
            'metadata'    => 'meta veriler',
        ];
    }
}
