<?php

namespace App\Http\Controllers\Admin\Config\Test;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Traits\TelegramTrait;
use App\Models\Config;

class TelegramController extends Controller
{
    use TelegramTrait;

    private Config $configModel;

    public function __construct(Config $config)
    {
        $this->configModel = $config;
    }

    /**
     * 텔레그램 발송 확인
     * @method GET
     * @see /admin/config/test/telegram
     */
    public function index()
    {
        return view('admin.config.test.telegram', []);
    }

    /**
     * 텔레그램 발송 확인 실행
     * @method POST
     * @see /admin/config/test/telegram
     */
    public function store(Request $request)
    {
        $rules = [
            'message' => 'required|string',
        ];

        $attributes = [
            'message' => '보낼 내용'
        ];

        $posts = $this->validate($request, $rules, [], $attributes);

        $this->sendMessage($posts['message']);

        $message = '문자를 발송하였습니다.';
        return redirect()->route('admin.config.test.telegram.index')->with('message', $message);
    }
}
