<?php

namespace Database\Factories;

use App\Models\Version;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

use App\Models\Page;

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

    /**
     * Define the model's default state.
     *
     * @return array
     */
    public function definition()
    {
        return [
            'version_number' => $this->faker->randomNumber(2),
        ];
    }

    public function published()
    {
        return $this->state([
            'published_at' => now(),
        ]);
    }

    public function page()
    {
        return $this->state([
            'name' => $this->faker->firstName.$this->faker->randomNumber(3),
            'title' => $this->faker->lastName,
            'description' => $this->faker->sentence,
            'slug' => null,
            'theme' => $this->faker->optional()->randomElement(['dark']),
            'parent_page_id' => 1,
            'sort_order' => $this->faker->randomNumber(1),
            'unlisted' => 0,
            'show_sub_menu' => 0,
            'footer_color' => null,
            'footer_fg_photo_id' => null,
            'footer_bg_photo_id' => null,
            'publish_at' => null,
            'signed_url' => 0,
            'sibling_nav' => 0,
        ]);
    }

    public function blog()
    {
        return $this->state([
            'name' => $this->faker->firstName.$this->faker->randomNumber(3),
            'title' => $this->faker->lastName,
            'description' => $this->faker->sentence,
            'slug' => null,
            'theme' => $this->faker->optional()->randomElement(['dark']),
            'parent_page_id' => null,
            'sort_order' => $this->faker->randomNumber(1),
            'unlisted' => 0,
            'show_sub_menu' => 0,
            'footer_color' => null,
            'footer_fg_photo_id' => null,
            'footer_bg_photo_id' => null,
            'publish_at' => null,
            'signed_url' => 0,
            'sibling_nav' => 0,
        ]);
    }

    public function announcement()
    {
        return $this->state([
            'name' => $this->faker->firstName.$this->faker->randomNumber(3),
            'title' => $this->faker->lastName,
            'description' => $this->faker->sentence,
            'slug' => null,
            'theme' => $this->faker->optional()->randomElement(['dark']),
            'parent_page_id' => null,
            'sort_order' => $this->faker->randomNumber(1),
            'unlisted' => 0,
            'show_sub_menu' => 0,
            'footer_color' => null,
            'footer_fg_photo_id' => null,
            'footer_bg_photo_id' => null,
            'publish_at' => null,
            'signed_url' => 0,
            'sibling_nav' => 0,
        ]);
    }

    public function course()
    {
        return $this->state([
            'name' => $this->faker->firstName.$this->faker->randomNumber(3),
            'title' => null,
            'slug' => null,
            'theme' => $this->faker->optional()->randomElement(['dark']),
            'parent_page_id' => null,
            'sort_order' => 1,
            'unlisted' => 0,
            'show_sub_menu' => 0,
            'footer_color' => null,
            'footer_fg_photo_id' => null,
            'footer_bg_photo_id' => null,
            'publish_at' => null,
            'redirect' => null,
            'description' => null,
            'search_exclude' => 0,
            'signed_url' => 0,
            'sibling_nav' => 0,
        ]);
    }

    public function secondLevel()
    {
        return $this->state([
            'parent_page_id' => Page::factory(),
        ]);
    }

    public function slug()
    {
        return $this->state([
            'slug' => $this->faker->firstName,
        ]);
    }

    public function unlisted()
    {
        return $this->state([
            'unlisted' => 1,
        ]);
    }

    public function signedUrl()
    {
        return $this->state([
            'signed_url' => 1,
        ]);
    }

    public function internalRedirect()
    {
        $page = Page::factory()->create();
        $page->publish();
        return $this->state([
            'redirect' => $page->id,
        ]);
    }

    public function randomize()
    {
        return $this->state([
            'randomize' => $this->faker->numberBetween(2, 10),
        ]);
    }
}
