<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use ImovelZapAi\Conversations\Domain\Enums\MessagingConnectionStatus;
use ImovelZapAi\Conversations\Domain\Enums\MessagingProvider;
use ImovelZapAi\Conversations\Infrastructure\Persistence\Eloquent\TenantMessagingConfigModel;
use ImovelZapAi\Tenancy\Infrastructure\Persistence\Eloquent\TenantModel;

/**
 * @extends Factory<TenantMessagingConfigModel>
 */
class TenantMessagingConfigFactory extends Factory
{
    protected $model = TenantMessagingConfigModel::class;

    /**
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        return [
            'tenant_id' => TenantModel::factory(),
            'provider' => MessagingProvider::Evolution,
            'instance_name' => 'tenant-'.fake()->unique()->slug(2),
            'instance_token' => null,
            'phone_number_id' => null,
            'business_account_id' => null,
            'access_token' => null,
            'verify_token' => null,
            'connection_status' => MessagingConnectionStatus::Connected,
            'is_active' => true,
            'automation_enabled' => true,
        ];
    }

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

    public function metaCloud(): static
    {
        return $this->state(fn (): array => [
            'provider' => MessagingProvider::MetaCloud,
            'instance_name' => null,
            'phone_number_id' => (string) fake()->numerify('################'),
            'access_token' => 'test-access-token',
            'verify_token' => 'test-verify-token',
            'connection_status' => MessagingConnectionStatus::Connected,
        ]);
    }
}
