<?php
/**
 *
 * @file:ChannelController.php
 * @Date: 2023/6/8
 * @Time: 11:16
 */


namespace Modules\Operation\Http\Controllers;

use Catch\Base\CatchController;
use Catch\Exceptions\FailedException;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Modules\Operation\Http\Requests\AddChannelRequest;
use Modules\Operation\Service\ChannelServic;

class ChannelController extends CatchController
{
    /**
     *   频道列表
     * name: list
     * @param Request $request
     * @return LengthAwarePaginator|Builder[]|Collection
     * date 2023/06/08 14:03
     */
    public function list(Request $request)
    {
        $param = $request->all();
        return ChannelServic::ChannelList($param);
    }

    /**
     *  编辑
     * name: add
     * @param AddChannelRequest $request
     * @return string|void
     * date 2023/06/08 15:18
     */
    public function add(AddChannelRequest $request)
    {
        $param = $request->validated();
        return ChannelServic::addChannel($param);
    }

    /*
    *  更新状态
    */
    public function enableStatus($id)
    {
        if ($id <  1){
            throw  new  FailedException("id不正确");
        }
        return ChannelServic::enableChannel($id);
    }

    // 保存配置
    public function setting($id,Request $request){
        if ($id <  1){
            throw  new  FailedException("id不正确");
        }
        if(!$request->has('duanjus')){
            throw  new  FailedException("配置项必填");
        }
        $set = $request->input('duanjus', []);
        return ChannelServic::setChannel($id,$set);
    }

    // 删除
    public function del($id){
        ChannelServic::delChannel($id);
    }
}
