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

use app\adminapi\controller\BaseAdminController;
use app\service\admin\channel\ChannelService;
use app\validate\admin\ChannelValidator;
use app\validate\domain\ChannelDomainValidator;
use think\Request;


/**
 * 渠道管理控制器
 * 渠道配置、支付设置、底部导航、通知中心
 * @package app\adminapi\controller\channel
 */
class Channel extends BaseAdminController
{
    /**
     * 渠道列表
     * @return \think\response\Json
     */
    public function list()
    {
        return json($this->app->make(ChannelService::class)->list());
    }

    /**
     * 渠道详情
     * @param string $channel
     * @return \think\response\Json
     */
    public function detail(string $channel)
    {
        $this->validate(['channel' => $channel], ChannelValidator::class . '.detail');
        return json($this->app->make(ChannelService::class)->detail($channel));
    }

    /**
     * 渠道底部导航配置
     * @param Request $request
     * @return \think\response\Json
     */
    public function bottomNavConfig(Request $request)
    {
        return json($this->app->make(ChannelService::class)->bottomNavConfig($request));
    }

    /**
     * 保存渠道底部导航配置
     * @param Request $request
     * @return \think\response\Json
     */
    public function saveBottomNavConfig(Request $request)
    {
        $params = [
            'data' => $request->post('data', []),
        ];
        $this->validate($params, ChannelValidator::class . '.save_bottom_nav');
        $this->validateDomain($this->app->make(ChannelDomainValidator::class), $params, 'save_bottom_nav');
        return json($this->app->make(ChannelService::class)->saveBottomNavConfig($request));
    }


    /**
     * 保存渠道基础配置
     * @param string $channel
     * @param Request $request
     * @return \think\response\Json
     */
    public function saveBase(string $channel, Request $request)
    {
        $params = array_merge(['channel' => $channel], $request->post());
        $this->validate($params, ChannelValidator::class . '.save_base');
        return json($this->app->make(ChannelService::class)->saveBase($channel, $request));
    }

    /**
     * 渠道支付设置
     * @param Request $request
     * @return \think\response\Json
     */
    public function paymentsConfig(Request $request)
    {
        return json($this->app->make(ChannelService::class)->paymentsConfig($request));
    }

    /**
     * 保存渠道支付设置
     * @param string $channel
     * @param Request $request
     * @return \think\response\Json
     */
    public function savePayments(string $channel, Request $request)
    {
        $params = array_merge(['channel' => $channel], $request->post());
        $this->validate($params, ChannelValidator::class . '.save_payments');
        return json($this->app->make(ChannelService::class)->savePayments($channel, $request));
    }


    /**
     * 渠道通知中心
     * @return \think\response\Json
     */
    public function notificationCenter()
    {
        return json($this->app->make(ChannelService::class)->notificationCenter());
    }

    /**
     * 保存渠道通知中心
     * @param Request $request
     * @return \think\response\Json
     */

    public function saveNotificationCenter(Request $request)
    {
        return json($this->app->make(ChannelService::class)->saveNotificationCenter($request));
    }
}