repuve-backend-v1/database/factories/VehicleFactory.php
2025-10-21 17:23:54 -06:00

129 lines
4.1 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\Vehicle;
use App\Models\Owner;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Vehicle>
*/
class VehicleFactory extends Factory
{
protected $model = Vehicle::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$brands = [
'CHEVROLET G.M.C.',
'NISSAN MEXICANA',
'VOLKSWAGEN',
'FORD MOTOR COMPANY',
'TOYOTA',
'HONDA',
'MAZDA',
'KIA MOTORS',
'HYUNDAI',
];
$types = ['SEDAN', 'SUV', 'PICKUP', 'HATCHBACK', 'VAN'];
$colors = ['BLANCO', 'NEGRO', 'GRIS', 'ROJO', 'AZUL', 'PLATA'];
$municipalities = ['CENTRO', 'CÁRDENAS', 'COMALCALCO', 'CUNDUACÁN', 'HUIMANGUILLO'];
$year = fake()->numberBetween(2015, 2025);
$vin = $this->generateVIN();
$placa = $this->generatePlaca();
return [
'anio_placa' => (string) $year,
'placa' => $placa,
'numero_serie' => $vin,
'rfc' => 'GME' . fake()->numerify('######') . 'GJA',
'folio' => fake()->unique()->numerify('#######'),
'vigencia' => (string) ($year + 1),
'fecha_impresion' => fake()->date('d-m-Y'),
'qr_hash' => fake()->sha256(),
'valido' => fake()->boolean(95), // 95% válidos
'nombre' => strtoupper(fake()->company()),
'nombre2' => strtoupper(fake()->lexify('????*????')),
'municipio' => fake()->randomElement($municipalities),
'localidad' => 'VILLAHERMOSA',
'calle' => strtoupper(fake()->streetAddress()),
'calle2' => strtoupper(fake()->lexify('? ??*????')),
'tipo' => fake()->randomElement($types),
'tipo_servicio' => fake()->randomElement(['PARTICULAR', 'PUBLICO', 'OFICIAL']),
'marca' => fake()->randomElement($brands),
'linea' => strtoupper(fake()->word()),
'sublinea' => 'PAQ. "' . strtoupper(fake()->randomLetter()) . '" ' . strtoupper(fake()->word()),
'modelo' => $year,
'numero_motor' => strtoupper(fake()->bothify('??####??##')),
'descripcion_origen' => fake()->randomElement(['NACIONAL', 'IMPORTADO']),
'color' => fake()->randomElement($colors),
'codigo_postal' => fake()->numerify('86###'),
'serie_folio' => 'D' . fake()->unique()->numerify('#######'),
'sfolio' => fake()->unique()->numerify('#######'),
'nrpv' => $vin,
'owner_id' => Owner::factory(),
];
}
/**
* Generate a realistic VIN (17 characters)
*/
private function generateVIN(): string
{
$wmi = strtoupper(fake()->bothify('???')); // World Manufacturer Identifier
$vds = strtoupper(fake()->bothify('??????')); // Vehicle Descriptor Section
$check = fake()->randomDigit();
$year = strtoupper(fake()->randomLetter());
$plant = fake()->randomDigit();
$serial = fake()->numerify('######');
return $wmi . $vds . $check . $year . $plant . $serial;
}
/**
* Generate a Tabasco plate
*/
private function generatePlaca(): string
{
return strtoupper(fake()->bothify('???###?'));
}
/**
* Indicate that the vehicle belongs to a specific owner.
*/
public function forOwner(int $ownerId): static
{
return $this->state(fn (array $attributes) => [
'owner_id' => $ownerId,
]);
}
/**
* Create an imported vehicle
*/
public function imported(): static
{
return $this->state(fn (array $attributes) => [
'descripcion_origen' => 'IMPORTADO',
]);
}
/**
* Create a national vehicle
*/
public function national(): static
{
return $this->state(fn (array $attributes) => [
'descripcion_origen' => 'NACIONAL',
]);
}
}