<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'party_id'     => 'required|exists:parties,id',
            'sales_date'   => 'required|date',
            'invoice_no'   => 'nullable|string|max:50',
            'labour_charge'=> 'nullable|numeric|min:0',
            'car_rent'     => 'nullable|numeric|min:0',
            'other_charge' => 'nullable|numeric|min:0',
            'discount'     => 'nullable|numeric|min:0',
            'paid_amount'  => 'nullable|numeric|min:0',
            'account_id'   => 'nullable|exists:accounts,id',
            'payment_mode' => 'nullable|string|max:30',
            'remarks'      => 'nullable|string|max:500',
            'items'        => 'required|array|min:1',
            'items.*.yarn_id'  => 'required|exists:yarns,id',
            'items.*.lot_no'   => 'nullable|string|max:30',
            'items.*.bags'     => 'nullable|integer|min:0',
            'items.*.quantity' => 'required|numeric|min:0.01',
            'items.*.unit'     => 'nullable|string|max:10',
            'items.*.rate'     => 'required|numeric|min:0.01',
        ];
    }
}
