<?php

namespace App\Http\Requests\Concerns;

use App\Enums\ChargeBasis;
use Illuminate\Validation\Rule;

trait ValidatesDocumentSpaces
{
    /**
     * @return array<string, mixed>
     */
    protected function documentSpaceRules(bool $required = true): array
    {
        return [
            'spaces' => [$required ? 'required' : 'nullable', 'array', 'min:1'],
            'spaces.*.space_id' => ['required', 'integer', 'exists:spaces,id'],
            'spaces.*.setup_start' => ['nullable', 'date'],
            'spaces.*.event_start' => ['required', 'date'],
            'spaces.*.event_end' => ['required', 'date', 'after:spaces.*.event_start'],
            'spaces.*.breakdown_end' => ['nullable', 'date'],
            'spaces.*.seating_layout' => ['nullable', 'string', 'max:255'],
            'spaces.*.guest_count' => ['nullable', 'integer', 'min:0'],
            'spaces.*.unit_price' => ['nullable', 'numeric', 'min:0'],
            'spaces.*.charge_basis' => ['nullable', Rule::enum(ChargeBasis::class)],
            'spaces.*.notes' => ['nullable', 'string', 'max:1000'],
        ];
    }

    /**
     * Booking-level fields shared by invoice/quotation create forms.
     *
     * @return array<string, mixed>
     */
    protected function documentBookingFieldRules(): array
    {
        return [
            'event_name' => ['required_without:booking_id', 'nullable', 'string', 'max:255'],
            'event_type_id' => ['nullable', 'integer', 'exists:event_types,id'],
            'description' => ['nullable', 'string'],
            'event_start' => ['nullable', 'date'],
            'event_end' => ['nullable', 'date', 'after:event_start'],
            'contact_name' => ['nullable', 'string', 'max:255'],
            'contact_phone' => ['nullable', 'string', 'max:50'],
            'contact_email' => ['nullable', 'email', 'max:255'],
            'seating_arrangement' => ['nullable', 'string', 'max:255'],
            'coordinator_id' => ['nullable', 'integer', 'exists:users,id'],
            'customer_notes' => ['nullable', 'string'],
            'internal_notes' => ['nullable', 'string'],
        ];
    }
}
