87 lines
3 KiB
PHP
87 lines
3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Database\Factories;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Infra\Database\Models\ArcadiaBrand;
|
|
use Infra\Database\Models\IncoSheet;
|
|
|
|
/**
|
|
* @extends Factory<IncoSheet>
|
|
*/
|
|
final class IncoSheetFactory extends Factory
|
|
{
|
|
protected $model = IncoSheet::class;
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
#[\Override]
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'id' => (string) fake()->unique()->numberBetween(10000, 99999),
|
|
'name' => 'Poulet Rôti 1kg',
|
|
'label' => 'Poulet Rôti Classe A',
|
|
'description' => 'Poulet prêt à cuire élevé en France',
|
|
'allegations' => [
|
|
'allegations' => ['Volaille française'],
|
|
'health' => [],
|
|
'nutrition' => ['Riche en protéines'],
|
|
'other' => [],
|
|
],
|
|
'sell_arguments' => 'Origine France garantie',
|
|
'preparation_advices' => 'Cuisson au four 1h à 180°C',
|
|
'tips' => 'Servir chaud',
|
|
'sell_familly' => 'Volaille',
|
|
'ingredients' => [
|
|
'Ingrédients' => ['Viande de poulet (98%)', 'Sel', 'Epices'],
|
|
],
|
|
'portions' => [
|
|
'lowPart' => 100,
|
|
'highPart' => 150,
|
|
'approximative' => false,
|
|
],
|
|
'allergens' => [
|
|
['code' => 1, 'label' => 'Gluten'],
|
|
],
|
|
'brand' => [
|
|
'code' => 1,
|
|
'label' => 'Le Gaulois',
|
|
],
|
|
'is_seasonal' => false,
|
|
'weight' => [
|
|
'netWeight' => 1000,
|
|
'grossWeight' => 1100,
|
|
'theoreticalAverage' => 1050,
|
|
],
|
|
'nutriscore' => [
|
|
'grade' => 'A',
|
|
],
|
|
'storage_condition' => [
|
|
'instructions' => 'À conserver entre 0°C et 4°C',
|
|
],
|
|
'additives' => [
|
|
['code' => 'E300', 'label' => 'Acide ascorbique'],
|
|
],
|
|
'compo_id' => (string) fake()->numberBetween(10000, 99999),
|
|
];
|
|
}
|
|
|
|
#[\Override]
|
|
public function configure(): static
|
|
{
|
|
return $this->afterCreating(function (IncoSheet $sheet): void {
|
|
$raw = is_array($sheet->brand) ? $sheet->brand : [];
|
|
$code = isset($raw['code']) && is_numeric($raw['code']) ? (int) $raw['code'] : 1;
|
|
$label = isset($raw['label']) && is_string($raw['label']) ? $raw['label'] : (string) ($raw['libelle'] ?? 'Le Gaulois');
|
|
|
|
ArcadiaBrand::query()->firstOrCreate(
|
|
['code' => $code],
|
|
['libelle' => $label]
|
|
);
|
|
});
|
|
}
|
|
}
|