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 dics(params) {
    let sql = [];
    sql.push("SELECT");
    sql.push(params.attrs || "*");
    sql.push("FROM");
    sql.push(this.model.tableName);
    sql.push("WHERE 1 = 1");
    if (params.saas_id) {
      sql.push("AND saas_id = :saas_id");
    }
    return await this.customQuery(sql, params);
  }
}
module.exports = SaasMainDao;
