<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\CartItem;
use App\Models\Plan;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/** @extends Factory<CartItem> */
class CartItemFactory extends Factory
{
    protected $model = CartItem::class;

    /** @return array<string, mixed> */
    public function definition(): array
    {
        return [
            'user_id' => User::factory(),
            'session_id' => null,
            'plan_id' => Plan::factory(),
            'billing_cycle' => $this->faker->randomElement(['monthly', 'quarterly', 'semi_annual', 'annual']),
            'quantity' => $this->faker->numberBetween(1, 3),
            'config_selections' => null,
            'provisioning_config' => null,
            'coupon_code' => null,
        ];
    }

    public function forSession(string $sessionId): static
    {
        return $this->state(fn (): array => [
            'user_id' => null,
            'session_id' => $sessionId,
        ]);
    }
}
