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

  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
    });
  }
}
module.exports = SaasMainDao;
