const system = require("../../../system");
const Dao = require("../../dao.base");
class SaasmerchantConsumeDao extends Dao {
  constructor() {
    super(Dao.getModelName(SaasmerchantConsumeDao));
  }

  async listByIds(ids, attrs) {
    if (!ids || ids.length == 0) {
      return [];
    }
    attrs = attrs || "*";
    let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE id IN (:ids) `;
    return await this.customQuery(sql, {
      ids: ids
    });
  }

  async mapByIds(ids, attrs) {
    let result = {};
    let list = await this.listByIds(ids, attrs);
    if (!list || list.length == 0) {
      return result;
    }
    for (var item of list) {
      result[item.id] = item;
    }
    return result;
  }

  async bySaasId(saasId, attrs) {
    attrs = attrs || "*";
    let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE saas_id = :saasId `;
    return await this.customQuery(sql, {
      saasId: saasId
    });
  }

  async byChannelId(channelId, attrs) {
    attrs = attrs || "*";
    let sql = `SELECT ${attrs} FROM ${this.model.tableName} WHERE channel_id = :channelId `;
    return await this.customQuery(sql, {
      channelId: channelId
    });
  }

  async countByCondition(params) {
    this.setCondition();
    return 0;
  }

  async listByCondition(params) {
    params.startRow = Number(params.startRow || 0);
    params.pageSize = Number(params.pageSize || 10);
    this.setCondition();
    return [];
  }
  setCondition(sql, params) {
    if (!params || !sql) {
      return;
    }
    if (params.saas_id) {
      sql.push("AND saas_id = :saas_id");
    }
    if (params.saas_merchant_id) {
      sql.push("AND saas_merchant_id = :saas_merchant_id");
    }
    if (params.createBegin) {
      sql.push("AND created_at >= :createBegin");
    }
    if (params.createEnd) {
      sql.push("AND created_at <= :createEnd");
    }
  }
}
module.exports = SaasmerchantConsumeDao;
