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

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