text: 'use strict';
  
  var hat = require('hat');
  var Constants = require('../constants');
  
  var Feature = function Feature(ctx, geojson) {
    this.ctx = ctx;
    this.properties = geojson.properties || {};
    this.coordinates = geojson.geometry.coordinates;
    this.id = geojson.id || hat();
    this.type = geojson.geometry.type;
  };
  
  Feature.prototype.changed = function () {
    this.ctx.store.featureChanged(this.id);
  };
  
  Feature.prototype.incomingCoords = function (coords) {
    this.setCoordinates(coords);
  };
  
  Feature.prototype.setCoordinates = function (coords) {
    this.coordinates = coords;
    this.changed();
  };
  
  Feature.prototype.getCoordinates = function () {
    return JSON.parse(JSON.stringify(this.coordinates));
  };
  
  Feature.prototype.setProperty = function (property, value) {
    this.properties[property] = value;
  };
  
  Feature.prototype.toGeoJSON = function () {
    return JSON.parse(JSON.stringify({
      id: this.id,
      type: Constants.geojsonTypes.FEATURE,
      properties: this.properties,
      geometry: {
        coordinates: this.getCoordinates(),
        type: this.type
      }
    }));
  };
  
  Feature.prototype.internal = function (mode) {
    var properties = {
      id: this.id,
      meta: Constants.meta.FEATURE,
      'meta:type': this.type,
      active: Constants.activeStates.INACTIVE,
      mode: mode
    };
  
    if (this.ctx.options.userProperties) {
      for (var name in this.properties) {
        properties['user_' + name] = this.properties[name];
      }
    }
  
    return {
      type: Constants.geojsonTypes.FEATURE,
      properties: properties,
      geometry: {
        coordinates: this.getCoordinates(),
        type: this.type
      }
    };
  };
  
  module.exports = Feature;