<?php

namespace App\Service;

use App\Models\AdminConfig;
use Illuminate\Support\Arr;

class AdminConfigService
{
    public const TYPE_DEFAULT = 1;  // 基础

    public const STATUS_OPEN = 1;   // 开启状态

    public static array $typeLabel = [
        self::TYPE_DEFAULT => '基础'
    ];

    /**
     * 获取用户oss配置
     *
     * @param int $adminUsersId
     * @return array|mixed
     */
    public function getAdminUserOssConfig()
    {
        $oldConfig = [];
        $config = AdminConfig::where('type', self::TYPE_DEFAULT)
            ->where('status', self::STATUS_OPEN)
            ->first();
        if (filled($config)) {
            $oldConfig = $config->config;
            $oldConfig = Arr::only($oldConfig, ['oss']);
        }
        $oss = [];
        if (filled($oldConfig)) {
            $oss = [
                'driver' => 'oss',
                'access_id' => $oldConfig['oss']['access_id'] ?? '',
                'access_key_id' => $oldConfig['oss']['access_id'] ?? '',
                'access_key' => $oldConfig['oss']['access_key_secret'] ?? '',
                'access_key_secret' => $oldConfig['oss']['access_key_secret'] ?? '',
                'bucket' => $oldConfig['oss']['bucket'] ?? '',
                'endpoint' => $oldConfig['oss']['endpoint'] ?? '',
                'endpoint_internal' => '',
                'cdnDomain' => $oldConfig['oss']['cdnDomain'] ?? '',
                'ssl' => false,
                'isCName' => false,
                'debug' => true,
            ];
        }
        return $oss;
    }
}
