<?php

declare(strict_types=1);

namespace KupShop\GTMBundle\ServerSideGTMEvent;

use Query\Operator;

trait FetchUsersStatsOrderData
{
    public function fetchUsersStatsOrderData(\Order $order): array
    {
        return sqlQueryBuilder()
            ->select('DATE(max(date_created)) last_date, DATE(min(date_created)) first_date, count(date_created) count')
            ->from('orders')
            ->where(Operator::like(['invoice_email' => $order->invoice_email]))
            ->andWhere(Operator::not(Operator::equals(['id' => $order->id])))
            ->execute()->fetchAssociative();
    }
}
