<?php
namespace Database\Factories;
use App\Modules\Order\Models\Order;
use App\Modules\User\Models\User;
use App\Modules\Vendor\Models\Vendor;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class OrderFactory extends Factory
{
protected $model = Order::class;
public function definition(): array
{
$subtotal = fake()->randomFloat(2, 200, 5000);
return [
'order_number' => 'STP-' . now()->format('Ymd') . '-' . strtoupper(Str::random(5)),
'uuid' => (string) Str::uuid(),
'user_id' => User::factory(),
'vendor_id' => Vendor::factory(),
'shipping_address' => [
'name' => fake()->name(),
'phone' => '98' . fake()->numerify('########'),
'city' => 'Kathmandu',
'country' => 'Nepal',
],
'currency' => 'NPR',
'subtotal' => $subtotal,
'discount_amount' => 0,
'coupon_discount' => 0,
'shipping_amount' => 100,
'tax_amount' => round($subtotal * 0.13, 2),
'total_amount' => $subtotal + 100 + round($subtotal * 0.13, 2),
'status' => 'pending',
'payment_method' => 'cod',
'payment_status' => 'pending',
'vendor_payout_amount' => round($subtotal * 0.9, 2),
'payout_processed' => false,
];
}
public function delivered(): static
{
return $this->state([
'status' => 'delivered',
'delivered_at' => now()->subDays(2),
]);
}
public function cancelled(): static
{
return $this->state([
'status' => 'cancelled',
'cancelled_at' => now()->subDay(),
]);
}
public function returned(): static
{
return $this->state([
'status' => 'returned',
'delivered_at' => now()->subDays(3),
]);
}
public function refunded(): static
{
return $this->state(['status' => 'refunded']);
}
public function paid(): static
{
return $this->state([
'payment_status' => 'paid',
'paid_at' => now()->subHour(),
]);
}
}