<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rule;

use App\Models\Supplier;

class SupplierProductAddEdit extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
		return Auth::user()->isWholesaler();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules(Request $request)
	{
		// @todo these are broadband requirements - perhaps move them to the broadband class.
		// @todo Enhance the validation so that extra_* values are not accepted if base_* values are not included.
		return [
			'id' => 'required|nullable',
			'offering_type' => ['required',Rule::in(Supplier::offeringTypeKeys()->toArray())],
			'supplier_detail_id' => 'required|exists:supplier_details,id',
			'active' => 'sometimes|accepted',
			'extra_shaped' => 'sometimes|accepted',
			'extra_charged' => 'sometimes|accepted',
			'product_id' => 'required|string|min:2',
			'product_desc' => 'required|string|min:2',
			'base_cost' => 'required|numeric|min:.01',
			'setup_cost' => 'nullable|numeric',
			'contract_term' => 'nullable|numeric|min:1',
			'metric' => 'nullable|numeric|min:1',
			'speed' => 'nullable|string|max:64',
			'technology' => 'nullable|string|max:255',
			'offpeak_start' => 'nullable|date_format:H:i',
			'offpeak_end' => 'nullable|date_format:H:i',
			'base_down_peak' => 'nullable|numeric',
			'base_up_peak' => 'nullable|numeric',
			'base_down_offpeak' => 'nullable|numeric',
			'base_up_offpeak' => 'nullable|numeric',
			'extra_down_peak' => 'nullable|numeric',
			'extra_up_peak' => 'nullable|numeric',
			'extra_down_offpeak' => 'nullable|numeric',
			'extra_up_offpeak' => 'nullable|numeric',
		];
	}
}
