<?php

namespace App\Http\Requests\Return;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        return [
            'original_order_id' => ['required', 'integer', 'exists:orders,id'],
            'customer_id' => ['nullable', 'integer', 'exists:customers,id'],
            'return_number' => ['nullable', 'string', 'max:50'],
            'reason' => ['required', Rule::in(['defective', 'wrong_item', 'customer_change_mind', 'overcharged', 'other'])],
            'reason_notes' => ['nullable', 'string'],
            'status' => ['nullable', Rule::in(['pending', 'approved', 'rejected', 'completed'])],
            'refund_method' => ['nullable', Rule::in(['cash', 'mpesa', 'store_credit', 'loyalty_points'])],
            'restocked' => ['nullable', 'boolean'],
            'device_id' => ['nullable', 'string', 'max:100'],
            'items' => ['required', 'array', 'min:1'],
            'items.*.order_item_id' => ['required', 'integer', 'exists:order_items,id'],
            'items.*.quantity' => ['required', 'numeric', 'gt:0'],
            'items.*.refund_amount' => ['nullable', 'numeric', 'min:0'],
            'items.*.condition' => ['nullable', Rule::in(['resellable', 'damaged', 'disposed'])],
        ];
    }
}
