/**
 * Created by shadeeka on 12/13/15.
 */
angular.module('app.services')
  .factory('propertyCache', ['$log', function ($log) {
    //var ipAddress="unknown";
    //var macAddress="unknown";
    //var networkStatus="unknown";

    var propertyCache = this;

    return {
      lineSeparator:"-",
      plans: {
        sessionsPlans: []
      },

      config: {
        dataIp: "",
        syncIp: "",
        factory: "",
        cluster :"",
        line: "",
        tenant: "",
        license:"",
        lineWithStation: "",
        lineWithOutStation: ""
      },

      factoryConfigs: {
        rwtogoodRectificationSteps: false,
        operator_change: false,
        operator_capturing: false,
        helper_capturing: false,
        member_capture : true,
        bulk_capturing : false,
        default_language : "",
        default_language_icon : "",
        count_track_mac_address : "",
        size_wise_events : [],
        default_bundle_sizes:[10,15,20,25]
      },

      day_start: {
        sessionPlan: "",
        style: "",
        members: 0,
        key1: "",
        key2: "",
        siluhoutteid: "",
        sessionPlanDetail:""
      },

      optional_day_start_data:{
        operators: 0,
        helpers: 0,
        buyerId: "",
        categoryId: "",
        sizeId: ""
      },

      siluhouttes: {
        silihoutteNames: []
      },

      planedStyles: {
        styleNames: []
      },

      startedStyles: {
        styleNames: []
      },

      pos: {
        poNames: []
      },

      colours: {
        colorCodes: []
      },

      operators: 0,
      helpers: 0,

      triggeredEvent :"",

      ipAddress: 'unknown',
      macAddress: 'unknown',
      networkStatus: 'unknown',
      currentUser: '',
      workingHour:1,

      isAddStyleUserLoggedIn: false,

      setIpAddress: function (data) {
        this.ipAddress = angular.extend(data)
      },
      setNetworkStatus: function (data) {
        this.networkStatus = angular.extend(data)
      },

      setCurrentUser: function (data) {
        this.currentUser = angular.extend(data);
      },
      setMacAddress: function (data) {
        this.macAddress = angular.extend(data)
      },

      setNetworkStatus: function (data) {
        this.networkStatus = angular.extend(data);
      },

      setConfig: function (data) {

        this.config = angular.extend(data);
        this.setStationData();
        $log.debug(this.config);

      },setStationData: function () {
        //set line fo
        var res = this.config["line"].split(this.lineSeparator);
        if(res.length > 1){
          this.config["lineWithStation"] = this.config["line"];
          this.config["lineWithOutStation"] = res[0];
        }else{
          this.config["lineWithStation"] = "";
          this.config["lineWithOutStation"] = "";
        }
      },

      setDayStart: function (data) {
        var sessionDetails = this.day_start["sessionPlanDetail"];
        this.day_start = angular.extend(data);
        this.day_start.sessionPlanDetail = sessionDetails;
        $log.debug(this.day_start);

      },

      setOptionalDayStart: function (data) {
        this.optional_day_start_data = angular.extend(data);
        $log.debug(this.optional_day_start_data);

      },

      setPlans: function (data) {

        this.plans = angular.extend(data);
        $log.debug("cache set plans ", this.plans);

      },

      setSiluhouttes: function (data) {
        this.siluhouttes = angular.extend(data);
        $log.debug("cache set siluhouttes ", this.siluhouttes);
      }, clearCacheData: function () {
        $log.debug("clearCacheData ");
        this.day_start["sessionPlan"] = "";
        this.day_start["style"] = "";
        this.day_start["members"] = 0;
        this.day_start["key1"] = "";
        this.day_start["key2"] = "";
        this.day_start["siluhoutteid"] = "";
      }, updateDayStartStyle: function (style) {
        $log.debug("Old style in cache ", this.day_start["style"] + " new " + style);
        if (style != undefined) {
          this.day_start["style"] = style;
          $log.debug("Cache set style ", this.day_start["style"]);
        }
      },

      setOperators: function (data) {
        this.operators = angular.extend(data);
        $log.debug(this.operators);
      },

      setHelpers: function (data) {
        this.helpers = angular.extend(data);
        $log.debug(this.helpers);
      },

      setTriggeredEvent: function (data) {
        this.triggeredEvent = angular.extend(data);
        $log.debug(this.triggeredEvent);
      },

      setSelectedStyles: function (data) {
        this.startedStyles.styleNames.push(data);
      },setWorkingHour: function (data) {
        this.workingHour = angular.extend(data)
      }

    };
  }]);
