<?php

namespace App\FormModel\rpc\v1;

use App\Listener\DbQueryExecutedListener;
use App\Model\AppArticle;
use Hyperf\Database\Query\Builder;
use Hyperf\DbConnection\Db;

class RpcIndexModel
{
    public function index(): array
    {
       $res = [];
       Db::beforeExecuting(function ($q) {
           var_dump($q);
       });

       $minPublishedTime = strtotime('-1 month');

//       $res['shows'] = [];
        $res['shows'] = AppArticle::formatQuery(['brand_name'])
            ->select(['cover', 'aid', 'title', 'brand as brand_name', 'images_count', 'view_count'])
            ->where([
                ['module', 0],
                ['published_status', 1],
                ['year', '>=', 2022],
                ['published_at', '>=', $minPublishedTime],
            ])->orderBy('year', 'DESC')->orderBy('published_at', 'DESC')->limit(25)->get()->toArray();

       $res['street'] = AppArticle::formatQuery(['location'])
           ->select(['cover', 'aid', 'title', 'brand as brand_name', 'images_count', 'view_count', 'location'])
           ->where([
               ['module', 1],
               ['published_status', 1],
               ['year', '>=', 2022],
               ['published_at', '>=', $minPublishedTime],
           ])->orderBy('year', 'DESC')->orderBy('published_at', 'DESC')->limit(25)->get()->toArray();


       return $res;
    }
}