<?php

namespace App\WhatsAppPlugins;

use App\Models\WhatsAppPlugin;
use App\WhatsAppPlugins\Contracts\BaseWhatsAppPlugin;

class SkypePlugin extends BaseWhatsAppPlugin
{
    public function getCode(): string
    {
        return 'skype';
    }

    public function getName(): string
    {
        return 'Skype';
    }

    public function getDescription(): string
    {
        return 'Chat or call via Skype.';
    }

    public function getIcon(): string
    {
        return 'skype';
    }

    public function getConfigFields(): array
    {
        return [
            [
                'key' => 'skype_id',
                'label' => 'Skype ID or Invite Link',
                'type' => 'text',
                'placeholder' => 'https://join.skype.com/invite/or28j5E44Zv4',
                'required' => true,
            ],
            [
                'key' => 'url',
                'label' => 'Skype URL',
                'type' => 'text',
                'placeholder' => 'https://join.skype.com/invite/or28j5E44Zv4',
                'required' => false,
            ],
        ];
    }

    public function validateConfig(array $config): array
    {
        $validated = [];
        $validated['skype_id'] = $config['skype_id'] ?? '';
        $validated['url'] = $config['url'] ?? $validated['skype_id'];
        return $validated;
    }

    public function isConfigured(WhatsAppPlugin $plugin): bool
    {
        $config = $plugin->config ?? [];
        return !empty($config['skype_id']);
    }

    public function getChatUrl(WhatsAppPlugin $plugin): string
    {
        $config = $plugin->config ?? [];
        return $config['url'] ?? $config['skype_id'] ?? '';
    }
}
