const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");
class ProducttypeService extends ServiceBase {
  constructor() {
    super("aggregation", ServiceBase.getDaoName(ProducttypeService));
  }
  async create(pobj) {
    let code = await this.getBusUid("mmc");
    pobj.code = code;
    if (!pobj.code) {
      return system.getResultFail(-101, "编码不能为空");
    }
    if (!pobj.pic_url) {
      return system.getResultFail(-102, "图标不能为空");
    }
    if (!pobj.sequence) {
      return system.getResultFail(-103, "排序不能为空");
    }
    if (!pobj.jump_link_type && !pobj.jump_link) {
      return system.getResultFail(-104, "连接不能为空");
    }
    if (pobj.name) {
      return system.getResultFail(-105, "名称不能为空");
    }
    if (pobj.name && pobj.name.length > 3) {
      return system.getResultFail(-106, "名称最多4位字符");
    }
    return system.getResultSuccess(this.dao.create(pobj));
  }


  async update(pobj) {
    if (!pobj.pic_url) {
      return system.getResultFail(-101, "图标不能为空");
    }
    if (!pobj.sequence) {
      return system.getResultFail(-102, "排序不能为空");
    }
    if (!pobj.jump_link_type && !pobj.jump_link) {
      return system.getResultFail(-104, "连接不能为空");
    }
    if (pobj.name) {
      return system.getResultFail(-105, "名称不能为空");
    }
    if (pobj.name && pobj.name.length > 3) {
      return system.getResultFail(-106, "名称最多4位字符");
    }
    return system.getResultSuccess(this.dao.update(pobj));
  }
}
module.exports = ProducttypeService;