require "./setup"

Wkbk::Article.destroy_all
Wkbk::Book.destroy_all

user = User.admin
book = user.wkbk_books.create!(key: 1)
book.articles << user.wkbk_articles.create!(key: 1)
book.articles << user.wkbk_articles.create!(key: 2)
book.articles.first.books.include?(book) # => true

user = User.bot
book = user.wkbk_books.create!(key: 2)
book.articles << user.wkbk_articles.create!(key: 3)
book.articles << user.wkbk_articles.create!(key: 4)
book.articles.first.books.include?(book) # => true

user = User.admin
user.wkbk_bookships.count             # => 2
user.wkbk_active_articles.pluck(:key) # => ["1", "2"]
user.wkbk_active_books.pluck(:key)    # => ["1", "1"]

user.wkbk_articles.first.destroy
user.wkbk_active_articles.pluck(:key) # => ["2"]
user.wkbk_active_books.pluck(:key)    # => ["1"]

tp Wkbk::Book
tp Wkbk::Article
tp Wkbk::Bookship
# >> |----+-----+---------+-----------+-------------+-------+---------------+-----------------+---------------------------+---------------------------|
# >> | id | key | user_id | folder_id | sequence_id | title | description   | bookships_count | created_at                | updated_at                |
# >> |----+-----+---------+-----------+-------------+-------+---------------+-----------------+---------------------------+---------------------------|
# >> | 92 |   1 |       6 |        12 |           1 |     1 | (description) |               0 | 2021-02-11 12:54:32 +0900 | 2021-02-11 12:54:32 +0900 |
# >> | 93 |   2 |       7 |        12 |           1 |     2 | (description) |               0 | 2021-02-11 12:54:33 +0900 | 2021-02-11 12:54:33 +0900 |
# >> |----+-----+---------+-----------+-------------+-------+---------------+-----------------+---------------------------+---------------------------|
# >> |-----+-----+---------+-----------+------------+-------------------------------------------------+-----------+----------------------------------+-------------+-------------------+----------+-----------+---------------------+------------+---------------------------+---------------------------+----------------------------+---------------+----------------|
# >> | id  | key | user_id | folder_id | lineage_id | init_sfen                                       | viewpoint | title                            | description | direction_message | turn_max | mate_skip | moves_answers_count | difficulty | created_at                | updated_at                | moves_answer_validate_skip | user_tag_list | owner_tag_list |
# >> |-----+-----+---------+-----------+------------+-------------------------------------------------+-----------+----------------------------------+-------------+-------------------+----------+-----------+---------------------+------------+---------------------------+---------------------------+----------------------------+---------------+----------------|
# >> | 159 |   2 |       6 |        10 |         25 | 7nl/7k1/9/7pp/6N2/9/9/9/9 b GS2r2b3g3s2n3l16p 1 | black     | 50fd1083a7dc86310545d7edb078119d |             |                   |        0 | false     |                   0 |          1 | 2021-02-11 12:54:32 +0900 | 2021-02-11 12:54:32 +0900 |                            |               |                |
# >> | 160 |   3 |       7 |        10 |         25 | 7nl/7k1/9/7pp/6N2/9/9/9/9 b GS2r2b3g3s2n3l16p 1 | black     | 81aab361147cf02039878c36ec1bda6c |             |                   |        0 | false     |                   0 |          1 | 2021-02-11 12:54:33 +0900 | 2021-02-11 12:54:33 +0900 |                            |               |                |
# >> | 161 |   4 |       7 |        10 |         25 | 7nl/7k1/9/7pp/6N2/9/9/9/9 b GS2r2b3g3s2n3l16p 1 | black     | cb49a6dd8d4b7bfc49c72b30c4a02ab5 |             |                   |        0 | false     |                   0 |          1 | 2021-02-11 12:54:33 +0900 | 2021-02-11 12:54:33 +0900 |                            |               |                |
# >> |-----+-----+---------+-----------+------------+-------------------------------------------------+-----------+----------------------------------+-------------+-------------------+----------+-----------+---------------------+------------+---------------------------+---------------------------+----------------------------+---------------+----------------|
# >> |-----+---------+---------+------------+----------+---------------------------+---------------------------|
# >> | id  | user_id | book_id | article_id | position | created_at                | updated_at                |
# >> |-----+---------+---------+------------+----------+---------------------------+---------------------------|
# >> | 148 |       6 |      92 |        159 |        0 | 2021-02-11 12:54:32 +0900 | 2021-02-11 12:54:32 +0900 |
# >> | 149 |       7 |      93 |        160 |        0 | 2021-02-11 12:54:33 +0900 | 2021-02-11 12:54:33 +0900 |
# >> | 150 |       7 |      93 |        161 |        1 | 2021-02-11 12:54:33 +0900 | 2021-02-11 12:54:33 +0900 |
# >> |-----+---------+---------+------------+----------+---------------------------+---------------------------|
