<?php

namespace App\Distributor\Repositories;

use App\Libraries\RpcClient;
use App\Models\NullModel as Model;
use Dcat\Admin\Repositories\EloquentRepository;
use Dcat\Admin\Show;

/*
 * RPC调用相册
 */

class RpcAlbumFolder extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;

    public $albumFolder = [];

    public function __construct($modelOrRelations = [])
    {
        $this->initModel($modelOrRelations);
        $distInfo = DistAdminDistributor::getInfo();
        $albumFolder = empty($distInfo->album_folder) ? [] : json_decode($distInfo->album_folder,true);

        $this->albumFolder = $albumFolder;
    }

    /*
     * RPC调用
     */
    public function execute($method, $params = [])
    {
        return RpcClient::albumExecute($method, $params);
    }

    /*
     * 获取相册文件夹列表
     * $inIds 传入的相册ID数组，为空时获取全部相册
     */
    public static function selectOptions($lang = 'en') {
        $self = new self();
        $inIds = $self->albumFolder;
        if ($lang == 'en') {
            $result = $self->execute('siteAlbumFolderSelectOptionsEn', ['inIds' => $inIds]);
        } else {
            $result = $self->execute('siteAlbumFolderSelectOptions', ['inIds' => $inIds]);
        }

        $data = $result['data'] ?? [];
        return $data;
    }
}
