<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

use App\Models\Course;
use App\Models\Version;

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

    public function configure()
    {
        return $this->afterCreating(function (Course $course) {
            $version = Version::factory()->course()->create([
                'versionable_type' => get_class($course),
                'versionable_id' => $course->id,
            ]);
        });
    }

    public function published()
    {
        return $this->state([
            'published_version_id' => Version::factory()->published()->for(Course::factory(), 'versionable'),
        ]);
    }

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