const system = require("../../../system");
const ServiceBase = require("../../svems.base")
const settings = require("../../../../config/settings")
class ChannelService extends ServiceBase {
  constructor() {
    super();
  }

  async dics(params) {
    var rs = await this.callms("merchant", "channelDics", params || {});
    return rs;
  }

  async page(params) {
    var rs = await this.callms("merchant", "channelPage", params);
    return rs;
  }

  async save(params) {
    var rs = await this.callms("merchant", "channelSave", params);
    return rs;
  }

  async info(params) {
    var rs = await this.callms("merchant", "channelInfo", params);
    return rs;
  }

  async mapByIds(params) {
    var rs = await this.callms("merchant", "channelMapByIds", params);
    return rs;
  }

  async setChannel(rows) {
    if (!rows) {
      return;
    }

    let channelIds = [];
    for (let row of rows) {
      if (!row) {
        continue;
      }
      if (row.channel_id) {
        channelIds.push(row.channel_id);
      }
    }
    if (channelIds.length == 0) {
      return;
    }
    let map = await this.mapByIds({
      ids: channelIds
    }) || {};
    map = map.data || {};
    for (let row of rows) {
      row.channel = map[row.channel_id] || {};
    }
  }

  async setChannel2(rows) {
    if (!rows) {
      return;
    }

    let channelIds = [];
    for (let row of rows) {
      if (!row) {
        continue;
      }
      if (row.owner_channel_id) {
        channelIds.push(row.owner_channel_id);
      }
    }
    if (channelIds.length == 0) {
      return;
    }
    let map = await this.mapByIds({
      ids: channelIds
    }) || {};
    map = map.data || {};
    for (let row of rows) {
      row.owner_channel = map[row.owner_channel_id] || {};
    }
  }
}
module.exports = ChannelService;