<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SalesOrderRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [

            'client_id' => 'required|exists:clients,id',

            'order_date' => 'required|date',

            'delivery_date' => 'required|date',

            'remarks' => 'nullable|string',

            'payment_terms' => 'nullable|string',
            
             'sales_person_id' =>
            'required|exists:users,id',

            'items' => 'required|array|min:1',

            'items.*.product_id' => 'required|exists:products,id',

            'items.*.quantity' => 'required|integer|min:1',

            'items.*.unit_price' => 'required|numeric|min:0',

            'items.*.discount' => 'nullable|numeric|min:0',
            
            
             

        ];
    }

    public function messages(): array
    {
        return [

            'items.required' => 'At least one product is required.',

            'items.*.product_id.required' => 'Please select a product.',

            'items.*.quantity.required' => 'Quantity is required.',

            'items.*.unit_price.required' => 'Unit price is required.'

        ];
    }
}