2025-10-21 17:23:54 -06:00

129 lines
3.9 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\File;
use App\Models\Record;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\File>
*/
class FileFactory extends Factory
{
protected $model = File::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
$fileTypes = [
['name' => 'Foto frontal del vehículo', 'ext' => 'jpg'],
['name' => 'Foto lateral derecha del vehículo', 'ext' => 'jpg'],
['name' => 'Foto lateral izquierda del vehículo', 'ext' => 'jpg'],
['name' => 'Foto trasera del vehículo', 'ext' => 'jpg'],
['name' => 'Foto del NIV/VIN', 'ext' => 'jpg'],
['name' => 'Tarjeta de circulación', 'ext' => 'pdf'],
['name' => 'Factura original', 'ext' => 'pdf'],
['name' => 'Comprobante de domicilio', 'ext' => 'pdf'],
['name' => 'Identificación oficial del propietario', 'ext' => 'pdf'],
['name' => 'Constancia de inscripción', 'ext' => 'pdf'],
];
$fileType = fake()->randomElement($fileTypes);
$timestamp = now()->timestamp . '_' . fake()->numberBetween(1000, 9999);
$fileName = $timestamp . '.' . $fileType['ext'];
return [
'name' => $fileType['name'],
'path' => 'records/' . $fileName,
'md5' => md5(fake()->uuid()),
'record_id' => Record::factory(),
];
}
/**
* Indicate that the file is an image
*/
public function image(): static
{
$imageTypes = [
'Foto frontal del vehículo',
'Foto lateral derecha del vehículo',
'Foto lateral izquierda del vehículo',
'Foto trasera del vehículo',
'Foto del NIV/VIN',
];
return $this->state(function (array $attributes) use ($imageTypes) {
$name = fake()->randomElement($imageTypes);
$timestamp = now()->timestamp . '_' . fake()->numberBetween(1000, 9999);
return [
'name' => $name,
'path' => 'records/' . $timestamp . '.jpg',
];
});
}
/**
* Indicate that the file is a PDF document
*/
public function pdf(): static
{
$pdfTypes = [
'Tarjeta de circulación',
'Factura original',
'Comprobante de domicilio',
'Identificación oficial del propietario',
'Constancia de inscripción',
];
return $this->state(function (array $attributes) use ($pdfTypes) {
$name = fake()->randomElement($pdfTypes);
$timestamp = now()->timestamp . '_' . fake()->numberBetween(1000, 9999);
return [
'name' => $name,
'path' => 'records/' . $timestamp . '.pdf',
];
});
}
/**
* Indicate that the file belongs to a specific record
*/
public function forRecord(int $recordId): static
{
return $this->state(fn (array $attributes) => [
'record_id' => $recordId,
]);
}
/**
* Create a vehicle photo file
*/
public function vehiclePhoto(): static
{
$photoTypes = [
'Foto frontal del vehículo',
'Foto lateral derecha del vehículo',
'Foto lateral izquierda del vehículo',
'Foto trasera del vehículo',
];
return $this->state(function (array $attributes) use ($photoTypes) {
$name = fake()->randomElement($photoTypes);
$timestamp = now()->timestamp . '_' . fake()->numberBetween(1000, 9999);
return [
'name' => $name,
'path' => 'records/' . $timestamp . '.jpg',
];
});
}
}