<?php

declare(strict_types=1);

namespace ImovelZapAi\Conversations\Application\Services;

use ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent\ConversationModel;
use ImovelZapAi\Properties\Domain\Enums\PropertyPurpose;
use ImovelZapAi\Properties\Infrastructure\Persistence\Eloquent\PropertyModel;

final class QualificationSkipPolicy
{
    public function shouldHandoffDirectly(
        PropertyModel $property,
        ConversationModel $conversation,
        bool $explicitVisitRequest,
    ): bool {
        if ($explicitVisitRequest) {
            return true;
        }

        if ($property->purpose === PropertyPurpose::Rent) {
            return true;
        }

        $rawFilters = $conversation->context['catalog']['filters'] ?? [];

        if (is_array($rawFilters) && ($rawFilters['purpose'] ?? null) === PropertyPurpose::Rent->value) {
            return true;
        }

        return false;
    }
}
