<?php

namespace App\Api\Controllers\Wechat;

use App\Api\WechatHandlers\EventMessageHandler;
use App\Api\WechatHandlers\FileMessageHandler;
use App\Api\WechatHandlers\ImageMessageHandler;
use App\Api\WechatHandlers\LinkMessageHandler;
use App\Api\WechatHandlers\LocationMessageHandler;
use App\Api\WechatHandlers\ShortVideoMessageHandler;
use App\Api\WechatHandlers\TextMessageHandler;
use App\Api\WechatHandlers\TransferMessageHandler;
use App\Api\WechatHandlers\VideoMessageHandler;
use App\Api\WechatHandlers\VoiceMessageHandler;
use EasyWeChat\Kernel\Messages\Message;
use Overtrue\LaravelWeChat\Controllers\Controller;

class IndexController extends Controller
{

    public function serve()
    {
        $app = app('wechat.official_account');

        $app->server->push(function ($message) {
            switch ($message['MsgType']) {
                case 'event':
                    return '收到事件消息';
                    break;
                case 'text':
                    return '收到文字消息';
                    break;
                case 'image':
                    return '收到图片消息';
                    break;
                case 'voice':
                    return '收到语音消息';
                    break;
                case 'video':
                    return '收到视频消息';
                    break;
                case 'location':
                    return '收到坐标消息';
                    break;
                case 'link':
                    return '收到链接消息';
                    break;
                case 'file':
                    return '收到文件消息';
                // ... 其它消息
                default:
                    return '收到其它消息';
                    break;
            }

            // ...
        });

        $app->server->push(EventMessageHandler::class, Message::EVENT);

        return $app->server->serve();
    }
}
