<?php

namespace App\Http\Controllers\Manage\Book;

use App\Http\Controllers\Controller;
use App\Http\Controllers\Manage\Book\Transformers\BadBookInfoTransformer;
use App\Modules\Book\Services\BadBookInfoService;
use DB;
use Hashids;
use Illuminate\Http\Request;
use OSS\Core\OssException;
use OSS\OssClient;
use Storage;

class BadBookController extends Controller
{
    /**
     * 添加不良书籍信息
     * @param Request $request
     * @return mixed
     */
    public function addBadBookInfo(Request $request)
    {
        $badInfo = trim($request->input('badInfo'));
        if (empty($badInfo)) {
            return response()->error('PARAM_EMPTY');
        }
        $data = BadBookInfoService::addBadInfo(compact('badInfo'));
        if ($data) {
            return response()->success();
        } else {
            return response()->error("HANDLE_FAILED");
        }
    }

    /**
     * 添加不良书籍信息
     * @param Request $request
     * @return mixed
     */
    public function editBadBookInfo(Request $request)
    {
        $id = $request->input('id');
        $badInfo = trim($request->input('badInfo'));
        if (empty($badInfo) || !$id) {
            return response()->error('PARAM_EMPTY');
        }
        $data = BadBookInfoService::editBadInfo(compact('id','badInfo'));
        if ($data) {
            return response()->success();
        } else {
            return response()->error("HANDLE_FAILED");
        }
    }

    /**获取不良书籍信息
     * @param Request $request
     * @return mixed
     */
    public function getBadBookInfos(Request $request)
    {
        $data = BadBookInfoService::getBadInfos(false);
        return response()->pagination(new BadBookInfoTransformer(), $data);
    }
}

