<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

use App\Models\Page;
use App\Models\Version;

class PageFactory extends Factory
{
    /**
     * The name of the factory's corresponding model.
     *
     * @var string
     */
    protected $model = Page::class;

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
        ];
    }

    public function configure()
    {
        return $this->afterCreating(function (Page $page) {
            $version = Version::factory()->page()->create([
                'versionable_type' => get_class($page),
                'versionable_id' => $page->id,
                'unlisted' => 1,
            ]);

            $page->refresh();
        });
    }

    /*
    public function published()
    {
        return $this->state([
            //'published_version_id' => Version::factory()->page()->published(),
        ]);
    }
     */

    public function unpublished()
    {
        return $this->state([
            'published_version_id' => null,
        ]);
    }
}
