<?php

namespace Database\Factories;

use App\Models\Language;
use App\Models\PlatformChannel;
use App\Models\PlatformInstance;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
 * @extends Factory<PlatformChannel>
 */
class PlatformChannelFactory extends Factory
{
    protected $model = PlatformChannel::class;

    public function definition(): array
    {
        return [
            'platform_instance_id' => PlatformInstance::factory(),
            'channel_id' => $this->faker->unique()->numberBetween(1, 999999),
            'name' => $this->faker->words(2, true),
            'display_name' => $this->faker->words(2, true),
            'language_id' => Language::factory(),
            'description' => $this->faker->optional()->sentence(),
            'is_active' => true,
        ];
    }

    public function inactive(): static
    {
        return $this->state(fn (array $attributes) => [
            'is_active' => false,
        ]);
    }

    public function community(?string $name = null): static
    {
        $communityName = $name ?: $this->faker->word();

        return $this->state(fn (array $attributes) => [
            'name' => $communityName,
            'display_name' => ucfirst($communityName),
        ]);
    }
}
