import DirectusAbstractStore from './directusAbstract.js'

/**
 *  Comments
 *
 *  @author Björn Hase <me@herr-hase.wtf>
 *  @license http://opensource.org/licenses/MIT The MIT License
 *  @link https://gitea.node001.net/HerrHase/super-fastify-directus.git
 *
 */

class CommentStore extends DirectusAbstractStore {

    /**
     *
     *
     *  @param  {String} endpoint
     *
     */
    constructor() {
        super('comments')
    }

    /**
     *  getting page by permalink
     *
     *  @param  {String} permalink
     *  @return {Object}
     *
     */
    find(page, uuid, limit = 20) {
        return this.items.readByQuery({
            fields: [
                'name',
                'content',
                'approved',
                'belongs_to.comments_id'
            ],
            filter: {
                approved   : true,
                belongs_to : {
                    comments_id: uuid
                }
            },
            limit  : limit,
            offset : ((page - 1) * limit)
        })
    }

    /**
     *  getting page by permalink
     *
     *  @param  {String} permalink
     *  @return {Object}
     *
     */
    page(page, uuid, limit = 20) {
        return this.items.readByQuery({
            fields: [
                'name',
                'content',
                'approved',
                'belongs_to.comments_id'
            ],
            filter: {
                approved   : true,
                belongs_to : {
                    comments_id: uuid
                }
            },
            limit  : limit,
            offset : ((page - 1) * limit)
        })
    }

}

export default CommentStore