<?php

namespace App\Http\Controllers\Manage\BadInfo;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Manage\BadInfo\Transformers\SensitiveChapterTransformer;
use App\Modules\BadInfo\Services\SensitiveChapterService;
use App\Modules\BadInfo\Services\BookSensitiveStatService;

use App\Modules\Book\Services\ChapterService;
use Illuminate\Http\Request;


class SensitiveChapterController extends Controller
{
    /**
     * 不良章节
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request)
    {
        $bid = $request->has('bid') ? $request->input('bid') : null;
        $time = BookSensitiveStatService::getMaxTime();
        if(!$bid) return response()->error('PARAM_ERROR');

        $chapters = SensitiveChapterService::getListObj(compact('bid','time'))->paginate();
        foreach ($chapters as $chapter)
        {
            $chapter->content = ChapterService::getChapterById($chapter->cid)->content;
        }
        return response()->pagination(new SensitiveChapterTransformer(), $chapters);
    }


}

