<?php

namespace App\DBRealTestSupport\TransactionSupported\DefinedService;

use App\DBRealTestSupport\TransactionSupported\TSRepositoryMother;
use App\Modules\DefinedService\Location\Domain\IdLocation;
use App\Modules\DefinedService\Location\Domain\Location;
use App\Modules\DefinedService\Location\Domain\LocationAbrv;
use App\Modules\DefinedService\Location\Domain\LocationDate;
use App\Modules\DefinedService\Location\Domain\LocationDateUpdate;
use App\Modules\DefinedService\Location\Domain\LocationLatitude;
use App\Modules\DefinedService\Location\Domain\LocationLongitude;
use App\Modules\DefinedService\Location\Domain\LocationName;
use App\Modules\DefinedService\Location\Domain\LocationRepository;
use App\Modules\DefinedService\Location\Domain\LocationStatus;
use App\Modules\DefinedService\Location\Domain\LocationVersion;
use Faker\Factory;

class TSLocationMother
{
    public static function random(
        ?IdLocation $idLocation = null,
        ?LocationVersion $version = null
    ): Location {
        $faker = Factory::create();
        return new Location(
            $idLocation ?? new IdLocation(0),
            new LocationDate(date('Y-m-d H:i:s', time() + rand(100000, 1000000))),
            new LocationDateUpdate(date('Y-m-d H:i:s', time() + rand(100000, 1000000))),
            new LocationName($faker->text(rand(5, 250))),
            new LocationAbrv($faker->text(rand(5, 50))),
            new LocationLatitude($faker->latitude(-90, 90)),
            new LocationLongitude($faker->longitude(-180, 180)),
            $version ?? new LocationVersion(rand(1, 1000)),
            new LocationStatus($faker->randomElement(LocationStatus::validValues())),
        );
    }

    public static function push(Location $model): Location
    {
        return TSRepositoryMother::push(LocationRepository::class, $model);
    }
}
