// Generated by CoffeeScript 1.12.7
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  hasProp = {}.hasOwnProperty;

Easydb4MigrationPlugin.StadtHanau = (function(superClass) {
  extend(StadtHanau, superClass);

  function StadtHanau() {
    return StadtHanau.__super__.constructor.apply(this, arguments);
  }

  StadtHanau.prototype.name = function() {
    return "stadt-hanau";
  };

  StadtHanau.prototype.payload = function(filename, json, update, store_file) {
    var _tags, add_tag, dfr, i, len, obj, ref, shortname;
    switch (json.import_type) {
      case "tags":
        _tags = [];
        add_tag = (function(_this) {
          return function(name, displayname) {
            return _tags.push({
              tag: {
                shortname: name,
                displayname: {
                  "de-DE": displayname
                },
                is_default: false,
                enabled: true,
                displaytype: "search",
                type: "individual"
              }
            });
          };
        })(this);
        json.tags.push({
          taggroup: {
            reference: "easydb4:itemtyp",
            type: "checkbox",
            displayname: {
              "de-DE": "Itemtyp"
            }
          },
          _tags: _tags
        });
        dfr = new CUI.Deferred();
        this._migration.query('SELECT id, name FROM "source.stadt_hanau.itemtyp" ORDER BY id').fail(dfr.reject).done((function(_this) {
          return function(result) {
            var i, len, ref, row;
            ref = result.rows;
            for (i = 0, len = ref.length; i < len; i++) {
              row = ref[i];
              add_tag("itemtyp:" + row.id, row.name);
            }
            return dfr.resolve();
          };
        })(this));
        return dfr.promise();
    }
    switch (json.objecttype) {
      case "bilder":
        ref = json.objects;
        for (i = 0, len = ref.length; i < len; i++) {
          obj = ref[i];
          if (!obj._tags) {
            obj._tags = [];
          }
          if (obj.bilder.lk_itemtyp_id) {
            shortname = obj.bilder.lk_itemtyp_id.itemtyp["lookup:_id"].easydb4_reference;
            obj._tags.push({
              "lookup:_id": {
                shortname: shortname
              }
            });
          }
        }
    }
  };

  return StadtHanau;

})(Easydb4MigrationPlugin);

ez5.session_ready((function(_this) {
  return function() {
    return Easydb4Migration.plugins.registerPlugin(Easydb4MigrationPlugin.StadtHanau);
  };
})(this));
