<?php

namespace App\Controller;

use App\Request\AreaRequest;
use App\Services\AreaService;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

class AreaController extends AbstractController
{
    /**
     * 获取省份信息
     * @return ResponseInterface
     */
    public function getProvince(): ResponseInterface
    {
        $areaService = new AreaService();

        $data = $areaService->getProvince();

        return $this->response->json($data);
    }

    /**
     * 获取城市信息
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function getCity(): ResponseInterface
    {
        $request = $this->container->get(AreaRequest::class);
        $request->scene('getCity')->validateResolved();

        $areaService = new AreaService();

        $data = $areaService->getCity();

        return $this->response->json($data);
    }

    /**
     * 获取区县信息
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    public function getCounty(): ResponseInterface
    {
        $request = $this->container->get(AreaRequest::class);
        $request->scene('getCounty')->validateResolved();

        $areaService = new AreaService();

        $data = $areaService->getCounty();

        return $this->response->json($data);
    }
}