<?php

namespace App\Http\Requests\Vendor;

use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        return [
            'user_id' => 'required|exists:users,id', // Ensure the user exists
            'business_name' => 'required|string|max:255',
            'contact_name' => 'required|string|max:255',
            'email' => 'required|email|unique:vendors,email',
            'phone' => 'required|string|max:20',
            'business_address' => 'required|string',
            'website' => 'nullable|url',

            // Vendor Type: must exist in vendor_categories.track_id
            'vendor_type' => ['required', 'array'],
            'vendor_type.*' => ['string', 'exists:vendor_categories,track_id'],

            // Print Services: array of valid sub-category track_ids
            'print_services' => ['required', 'array'],
            'print_services.*' => ['string', 'exists:vendor_sub_categories,track_id'],

            // Materials Sold: array of valid sub-category track_ids
            'materials_sold' => ['required', 'array'],
            'materials_sold.*' => ['string', 'exists:vendor_sub_categories,track_id'],

            'machine_types' => 'nullable|string',
            'turnaround_time' => 'nullable|string',
            'pricing_file' => 'nullable|file|mimes:pdf,jpeg,png,jpg,doc,docx|max:10240', // max 10MB
            'minimum_order_qty' => 'nullable|string',
            'cac_document' => 'nullable|file|mimes:pdf,jpeg,png,jpg,doc,docx|max:10240',  // max 10MB
            'additional_notes' => 'nullable|string',
        ];
    }
}
