*/ class ReservationFactory extends Factory { protected $model = Reservation::class; public function definition(): array { return [ 'spare_part_id' => SparePart::factory(), 'spare_part_order_id' => SparePartOrder::factory(), 'reclamation_id' => Reclamation::factory(), 'reserved_qty' => fake()->numberBetween(1, 10), 'with_documents' => fake()->boolean(), 'status' => Reservation::STATUS_ACTIVE, 'movement_id' => null, ]; } public function active(): static { return $this->state(fn (array $attributes) => [ 'status' => Reservation::STATUS_ACTIVE, ]); } public function issued(): static { return $this->state(fn (array $attributes) => [ 'status' => Reservation::STATUS_ISSUED, ]); } public function cancelled(): static { return $this->state(fn (array $attributes) => [ 'status' => Reservation::STATUS_CANCELLED, ]); } public function withDocuments(bool $withDocs = true): static { return $this->state(fn (array $attributes) => [ 'with_documents' => $withDocs, ]); } public function withQuantity(int $quantity): static { return $this->state(fn (array $attributes) => [ 'reserved_qty' => $quantity, ]); } public function forReclamation(Reclamation $reclamation): static { return $this->state(fn (array $attributes) => [ 'reclamation_id' => $reclamation->id, ]); } public function forSparePart(SparePart $sparePart): static { return $this->state(fn (array $attributes) => [ 'spare_part_id' => $sparePart->id, ]); } public function fromOrder(SparePartOrder $order): static { return $this->state(fn (array $attributes) => [ 'spare_part_order_id' => $order->id, 'spare_part_id' => $order->spare_part_id, 'with_documents' => $order->with_documents, ]); } }