const DBModule = require('./DBModule');

class Case extends DBModule {

  get table() {
    return 'case'
  }

  get primary() {
    return 'id'
  }

  get fields() {
    return [
      'id', 'title', 'content', 'cover', 'logo', 'label',
      'date', 'sort', 'link', 'address', 'hide', 'user_id', 'type', 
      'english_id', 'chinese_id', 'language', 'pro_type'
    ]
  }

  paging(page, limit, keyword = '', label, language) {
    let joinSql = '';

    label && (joinSql += `and label = '${label}'`);
    language && (joinSql += `and language = '${language}'`);

    let sql = `select {{header}} from \`case\` where title like '%${keyword}%' and hide=${this.hide} ${joinSql} order by \`sort\` asc`
    return super.paging({
      page,
      limit,
      start: page * limit,
      sql,
      paging: 1,
      headers: '*'
    })
  }
}

module.exports = exports = Case;