<?php

/**
 * Created by PhpStorm.
 * Date: 2017/3/31
 * Time: 14:02
 */

namespace App\Http\Controllers\QuickApp\Book\Transformers;

use Hashids;

class BookTransformer
{
    public function transform($book)
    {
        return [
            'book_id'                    => Hashids::encode($book->bid),
            'book_name'                  => $book->book_name,
            'book_summary'               => $book->intro,
            'book_author'                => $book->author,
            'cover_url'                  => $book->cover,
            'book_word_count'            => $book->size,
            'book_chapter_total'         => $book->chapter_count,
            'book_category_id'           => $book->category_id,
            'book_category'              => $book->category_name,
            'book_end_status'            => $book->status,
            'book_published_time'        => $book->updated_at ?? '',
            'copyright'                  => $book->copyright ?? '',
            'charge_type'                => $book->charge_type ?? '',
            'force_subscribe_chapter_id' => $book->force_subscribe_chapter_seq,
            'update_time'                => $book->updated_at ?? '',
            // 'is_on_shelf' => $book->is_on_shelf ?? 0,
            'book_price'                 => $book->price ?? 0,
            'keyword'                    => $book->keyword,
            'recommend_index'            => $book->recommend_index,
            'is_show_index_content'      => $book->is_show_index_content,
            'click_count'                => $book->click_count,
            'product_id'                 => $book->product_id,
            'sex_preference'             => $book->channel_name,
            'last_cid'                   => $book->last_cid,
            'last_chapter'               => $book->last_chapter,
            'first_cid'                  => $book->first_cid,
            'is_on_user_shelf'           => $book->is_on_user_shelf,
            'last_chapter_is_vip'        => $book->last_chapter_is_vip ?? 0,
            'is_need_charge'             => $book->is_need_charge ? 1 : 0,
            'record_chapter_id'          => $book->record_chapter_id ?? 0,
            'record_chapter_name'        => $book->record_chapter_name ?? '',
        ];
    }
}
