import BaseAPI from './baseContent.es6.js';
import { has } from 'lodash/object';

import Link from '../models/link.es6.js';
import Comment from '../models/comment.es6.js';

class ModListing extends BaseAPI {
  static dataCacheConfig = undefined;

  get requestCacheRules () {
    return undefined;
  }

  move = this.notImplemented('move');
  copy = this.notImplemented('copy');
  put = this.notImplemented('put');
  patch = this.notImplemented('patch');
  del = this.notImplemented('del');
  post = this.notImplemented('post');

  path(method, query={}) {
    const { subreddit, modPath } = query;
    return `r/${subreddit}/about/${modPath}.json`;
  }

  formatQuery (options) {
    options.sr_detail = 'true';

    return options;
  }

  formatBody(res) {
    const { body } = res;

    if (has(body, 'data.children.0')) {
      return body.data.children.map(c => {
        if (c.kind == 't3') {
          return new Link(c.data).toJSON();
        } else if (c.kind === 't1') {
          return new Comment(c.data).toJSON();
        }
      });
    }
  }
}

export default ModListing;

@@ -738,22 +738,21 @@
 %0A%0A  
-format
+parse
 Body(res
 ) %7B%0A
@@ -747,16 +747,29 @@
 Body(res
+, apiResponse
 ) %7B%0A    
@@ -837,23 +837,16 @@
 %7B%0A      
-return 
 body.dat
@@ -860,11 +860,15 @@
 ren.
-map
+forEach
 (c =
@@ -907,31 +907,46 @@
 %7B%0A          
-return 
+apiResponse.addResult(
 new Link(c.d
@@ -950,32 +950,33 @@
 c.data).toJSON()
+)
 ;%0A        %7D else
@@ -1009,23 +1009,38 @@
         
-return 
+apiResponse.addResult(
 new Comm
@@ -1059,16 +1059,17 @@
 toJSON()
+)
 ;%0A      

Normalize modlisting.