<?php

namespace App\Controller;

use App\Request\LoginRequest;
use App\Services\LoginService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;

/**
 * 登陆
 */
class LoginController extends AbstractController
{
    /**
     * 微信手机号登陆
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function wechatMobileLogin(): ResponseInterface
    {
        // 验证参数
        $request = $this->container->get(LoginRequest::class);
        $request->scene('wechatMobileLogin')->validateResolved();

        $LoginService = new LoginService();
        $data = $LoginService->wechatMobileLogin();
        return $this->response->json($data);
    }

    /**
     * 手机号登陆
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function mobileLogin(): ResponseInterface
    {
        // 验证参数
        $request = $this->container->get(LoginRequest::class);
        $request->scene('mobileLogin')->validateResolved();

        $LoginService = new LoginService();
        $data = $LoginService->mobileLogin();
        return $this->response->json($data);
    }

    /**
     * 微信授权接口
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     * @throws ClientExceptionInterface
     * @throws DecodingExceptionInterface
     * @throws RedirectionExceptionInterface
     * @throws ServerExceptionInterface
     * @throws TransportExceptionInterface
     */
    public function wxAuthorize(): ResponseInterface
    {
        // 验证参数
        $request = $this->container->get(LoginRequest::class);
        $request->scene('wxAuthorize')->validateResolved();

        $LoginService = new LoginService();
        $data = $LoginService->wxAuthorize();
        return $this->response->json($data);
    }
}