*/ class StreamFactory extends Factory { protected $model = Stream::class; public function definition(): array { $type = $this->faker->randomElement(StreamTypeEnum::cases()); return [ 'scenario_id' => null, // Set in test 'name' => $this->faker->words(3, true), 'type' => $type, 'amount' => $this->faker->numberBetween(5000, 200000), // $50 to $2000 'frequency' => $this->faker->randomElement([ StreamFrequencyEnum::DAILY, StreamFrequencyEnum::WEEKLY, StreamFrequencyEnum::MONTHLY, StreamFrequencyEnum::YEARLY, ]), 'start_date' => $this->faker->dateTimeBetween('-1 year', 'now'), 'end_date' => $this->faker->optional(0.2)->dateTimeBetween('now', '+1 year'), 'bucket_id' => null, // Only for expenses 'description' => $this->faker->optional()->sentence(), 'is_active' => true, ]; } public function scenario(Scenario $scenario): self { return $this->state(fn () => [ 'scenario_id' => $scenario->id, ]); } public function income(): self { return $this->state(fn (array $attributes) => [ 'type' => StreamTypeEnum::INCOME, 'bucket_id' => null, ]); } public function expense(): self { return $this->state(fn (array $attributes) => [ 'type' => StreamTypeEnum::EXPENSE, ]); } public function inactive(): self { return $this->state(fn (array $attributes) => [ 'is_active' => false, ]); } public function daily(): self { return $this->state(fn (array $attributes) => [ 'frequency' => StreamFrequencyEnum::DAILY, ]); } public function weekly(): self { return $this->state(fn (array $attributes) => [ 'frequency' => StreamFrequencyEnum::WEEKLY, ]); } public function monthly(): self { return $this->state(fn (array $attributes) => [ 'frequency' => StreamFrequencyEnum::MONTHLY, ]); } public function yearly(): self { return $this->state(fn (array $attributes) => [ 'frequency' => StreamFrequencyEnum::YEARLY, ]); } }