<?php

declare(strict_types=1);

namespace App\Controller;

use App\JsonRpc\AdServiceInterface;
//use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use App\Tools\Result;
use App\Constants\ErrorCode;
use Hyperf\Logger;
/**
 * Class AdController
 * @package App\Controller
 */
#[AutoController]
class AdController extends AbstractController
{

    /**
     * @var AdServiceInterface
     */
    #[Inject]
    private  $adServiceInterface;

    public function createAd()
    {
        $name = (string)$this->request->input('name', '');
        $gender = (string)$this->request->input('url', 0);
        $result = $this->adServiceInterface->createAd($name, $gender);
        return $result?Result::success($result['data']):Result::error($result['message']);
    }

    /**
     * @return array|void
     */
    public function getAdInfo()
    {
        $id = (int)$this->request->input('id');
        $result =  $this->adServiceInterface->getAdInfo($id);
//        $this->logger->info("ceshi--");
        if ($result['code'] != ErrorCode::SUCCESS) {
            return Result::error($result['message'],0);
        }
        return Result::success($result['data']);
    }
}