def bulk_create
      propertiesJSON = params["propertiesJSON"]
      unless propertiesJSON.is_a? Array
        propertiesJSON = JSON.parse propertiesJSON
      end
      new_props = []
      existing_props = []
      errors = []
      properties_params(propertiesJSON).each_with_index do |property_params, index|
        propertyJSON = propertiesJSON[index]
        if Pwb::Prop.where(reference: propertyJSON["reference"]).exists?
          existing_props.push Pwb::Prop.find_by_reference propertyJSON["reference"]
          # propertyJSON
        else
          begin
            new_prop = Pwb::Prop.create(property_params)
            # new_prop = Pwb::Prop.create(propertyJSON.except("features", "property_photos", "image_urls", "last_retrieved_at"))

            # create will use website defaults for currency and area_unit
            # need to override that
            if propertyJSON["currency"]
              new_prop.currency = propertyJSON["currency"]
              new_prop.save!
            end
            if propertyJSON["area_unit"]
              new_prop.area_unit = propertyJSON["area_unit"]
              new_prop.save!
            end

            # TODO - go over supported locales and save title and description
            # into them

            # if propertyJSON["features"]
            # TODO - process feature (currently not retrieved by PWS so not important) 
            #   new_prop.set_features=propertyJSON["features"]
            # end
            if propertyJSON["property_photos"]
              # uploading images can slow things down so worth setting a limit
              max_photos_to_process = 20
              # TODO - retrieve above as a param
              propertyJSON["property_photos"].each_with_index do |property_photo, index|
                if index > max_photos_to_process
                  return
                end
                photo = PropPhoto.create
                photo.sort_order = property_photo["sort_order"] || nil
                photo.remote_image_url = property_photo["url"]
                # photo.remote_image_url = property_photo["image"]["url"] || property_photo["url"]
                photo.save!
                new_prop.prop_photos.push photo
              end
            end

            new_props.push new_prop
          rescue => err
            errors.push err.message
            # logger.error err.message
          end
        end
      end

      return render json: {
        new_props: new_props,
        existing_props: existing_props,
        errors: errors
      }
    end
def bulk_create
      propertiesJSON = params["propertiesJSON"]
      unless propertiesJSON.is_a? Array
        propertiesJSON = JSON.parse propertiesJSON
      end
      new_props = []
      existing_props = []
      errors = []
      properties_params(propertiesJSON).each_with_index do |property_params, index|
        propertyJSON = propertiesJSON[index]
        if Pwb::Prop.where(reference: propertyJSON["reference"]).exists?
          existing_props.push Pwb::Prop.find_by_reference propertyJSON["reference"]
          # propertyJSON
        else
          begin
            new_prop = Pwb::Prop.create(property_params)
            # new_prop = Pwb::Prop.create(propertyJSON.except("features", "property_photos", "image_urls", "last_retrieved_at"))

            # create will use website defaults for currency and area_unit
            # need to override that
            if propertyJSON["currency"]
              new_prop.currency = propertyJSON["currency"]
              new_prop.save!
            end
            if propertyJSON["area_unit"]
              new_prop.area_unit = propertyJSON["area_unit"]
              new_prop.save!
            end

            # TODO - go over supported locales and save title and description
            # into them

            # if propertyJSON["features"]
            # TODO - process feature (currently not retrieved by PWS so not important) 
            #   new_prop.set_features=propertyJSON["features"]
            # end
            if propertyJSON["property_photos"]
              # uploading images can slow things down so worth setting a limit
              max_photos_to_process = 20
              # TODO - retrieve above as a param
              propertyJSON["property_photos"].each_with_index do |property_photo, index|
                if index > max_photos_to_process
                  return
                end
                photo = PropPhoto.create
                photo.sort_order = property_photo["sort_order"] || nil
                photo.remote_image_url = property_photo["url"]
                # photo.remote_image_url = property_photo["image"]["url"] || property_photo["url"]
                photo.save!
                new_prop.prop_photos.push photo
              end
            end

            new_props.push new_prop
          rescue => err
            errors.push err.message
            # logger.error err.message
          end
        end
      end

      return render json: {
        new_props: new_props,
        existing_props: existing_props,
        errors: errors
      }
    end
def set_default_currency
   @model
 end