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

use app\service\admin\BaseAdminService;
use app\service\domain\system\CoreConfigService;
use think\Request;


/**
 * Config Service
 * @package app\service\admin\system
 */
class ConfigService extends BaseAdminService
{

    /**
     * 获取系统配置
     * @param Request $request 请求对象
     * @return array
     */
    public function get(Request $request): array
    {
        return ['code' => 0, 'data' => $this->core()->getAdminConfig($request)];
    }


    /**
     * 获取基础配置选项
     * @param Request $request 请求对象
     * @return array
     */
    public function basicOptions(Request $request): array
    {
        return ['code' => 0, 'data' => $this->core()->getBasicOptions($request)];
    }


    /**
     * 保存系统配置
     * @param Request $request 请求对象
     * @return array
     */
    public function save(Request $request): array
    {
        $payload = $request->post('data');
        if (!is_array($payload)) {
            return ['code' => 1, 'msg' => ''];
        }

        return $this->core()->save($payload);
    }

    /**
     * 获取系统配置核心服务实例
     * @return CoreConfigService
     */
    private function core(): CoreConfigService
    {
        return $this->app->make(CoreConfigService::class);
    }
}