<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace app\service\domain\storage;

use app\repository\system\ConfigRepository;
use Core\service\BaseCoreService;


/**
 * Storage Config Service
 * @package app\service\domain\storage
 */
class StorageConfigService extends BaseCoreService
{
    /**
     * 获取当前存储驱动
     * @return string 当前存储驱动
     */
    public function driver(): string
    {
        $driver = $this->cfg('storage_driver', 'local');
        if (!in_array($driver, ['local', 'aliyun_oss', 'tencent_cos', 'qiniu_kodo'], true)) {
            return 'local';
        }
        return $driver;
    }

    /**
     * 获取阿里云OSS访问密钥ID
     * @return string 阿里云OSS访问密钥ID
     */
    public function aliyunAccessKeyId(): string
    {
        return $this->cfg('storage_aliyun_oss_access_key_id', '');
    }

    /**
     * 获取阿里云OSS访问密钥密钥
     * @return string 阿里云OSS访问密钥密钥
     */
    public function aliyunAccessKeySecret(): string
    {
        return $this->cfg('storage_aliyun_oss_access_key_secret', '');
    }

    /**
     * 获取阿里云OSS端点
     * @return string 阿里云
     */
    public function aliyunEndpoint(): string
    {
        return $this->cfg('storage_aliyun_oss_endpoint', '');
    }

    /**
     * 获取阿里云OSS存储桶
     * @return string 阿里云OSS存储桶
     */
    public function aliyunBucket(): string
    {
        return $this->cfg('storage_aliyun_oss_bucket', '');
    }

    /**
     * 获取腾讯云COS访问密钥ID
     * @return string 腾讯云COS访问密钥ID
     */
    public function tencentSecretId(): string
    {
        return $this->cfg('storage_tencent_cos_secret_id', '');
    }

    /**
     * 获取腾讯云COS访问密钥密钥
     * @return string 腾讯云COS访问密钥密钥
     */
    public function tencentSecretKey(): string
    {
        return $this->cfg('storage_tencent_cos_secret_key', '');
    }

    /**
     * 获取腾讯云COS区域
     * @return string 腾讯云COS区域
     */
    public function tencentRegion(): string
    {
        return $this->cfg('storage_tencent_cos_region', '');
    }

    /**
     * 获取腾讯云COS存储桶
     * @return string 腾讯云COS存储桶
     */
    public function tencentBucket(): string
    {
        return $this->cfg('storage_tencent_cos_bucket', '');
    }

    /**
     * 获取七牛云Kodo访问密钥
     * @return string 七牛云Kodo访问密钥
     */
    public function qiniuAccessKey(): string
    {
        return $this->cfg('storage_qiniu_access_key', '');
    }

    /**
     * 获取七牛云Kodo访问密钥密钥
     * @return string 七牛云Kodo访问密钥密钥
     */
    public function qiniuSecretKey(): string
    {
        return $this->cfg('storage_qiniu_secret_key', '');
    }

    /**
     * 获取七牛云Kodo存储桶
     * @return string 七牛云Kodo存储桶
     */
    public function qiniuBucket(): string
    {
        return $this->cfg('storage_qiniu_bucket', '');
    }

    /**
     * 获取七牛云Kodo域名
     * @return string 七牛云Kodo域名
     */
    public function qiniuDomain(): string
    {
        return $this->cfg('storage_qiniu_domain', '');
    }

    /**
     * 获取配置配置项
     * @param string $key 配置项键
     * @param string $default 默认值
     * @return string 配置项值
     */
    private function cfg(string $key, string $default = ''): string
    {
        /** @var ConfigRepository $repo */
        $repo = $this->app->make(ConfigRepository::class);
        return $repo->getString($key, $default);
    }
}
