const system = require("../../../system");
const Dao = require("../../dao.base");

class SaasOrderPayDao extends Dao {
  constructor() {
    super(Dao.getModelName(SaasOrderPayDao));
  }

  async findByOrderId(order_id) {
    let sql = `SELECT * FROM ${this.model.tableName} WHERE order_id = :order_id `;
    return await this.customQuery(sql, {order_id: order_id});
  }

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

    var list = await this.customQuery(sql.join(" "), {
      ids: ids
    });
    if (!list || list.length == 0) {
      return result;
    }
    for (var item of list) {
      result[item.id] = item;
    }
    return result;
  }
}

module.exports = SaasOrderPayDao;