<?php

use Mockery\MockInterface;
use Tricks\Monitoring\EloquentModels;
use Workbench\App\Models\TestModel;
use Workbench\App\Models\TestModelWithoutTimestamps;

function getEloquentModelsMock($models = null)
{
    return Mockery::mock(EloquentModels::class, function (MockInterface $mock) use ($models) {
        $mock
            ->shouldReceive('get')
            ->andReturn(collect($models ?? [getMockedTestModel()]));
    });
}

function getMockedTestModel($updatedAt = null)
{
    $instance = new TestModel();
    $instance->updated_at = $updatedAt ?? now()->createMidnightDate()->addHour();

    return Mockery::mock(TestModel::class, function (MockInterface $mock) use ($instance) {
        $mock->shouldReceive('latest')
            ->andReturn(collect([$instance]));
        $mock->shouldReceive('count')
            ->andReturn(1);
    }
    );
}

function getMockedEmptyTestModel()
{
    return Mockery::mock(TestModel::class, fn (MockInterface $mock) => $mock->shouldReceive('latest')
        ->once()
        ->andReturn(collect([]))
    );
}

function getMockedTestModelWithoutTimestamps()
{
    return Mockery::mock(TestModelWithoutTimestamps::class, function (MockInterface $mock) {
        $mock->shouldReceive('count')
            ->once()
            ->andReturn(1);
    });
}
