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

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

    async suggest(name) {
        var sql = "SELECT id, name FROM `e_merchant` WHERE deleted_at IS NULL ";
        var list = await this.customQuery(sql);
        return list || [];
    }

    async findMapByIds(ids, attrs) {
        var result = {};
        if (!ids || ids.length == 0) {
            return result;
        }
        attrs = attrs || "*";
        var sql = "SELECT " + attrs + " FROM e_merchant where id IN (:ids) ";
        var list = await this.customQuery(sql, {ids: ids});
        if (!list || list.length == 0) {
            return result;
        }

        for (var item of list) {
            result[item.id] = item;
        }

        return result;
    }
}

module.exports = MerchantDao;
