package com.hubspot.blazar.data.dao;


import java.util.Set;

import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.GetGeneratedKeys;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.customizers.SingleValueResult;

import com.google.common.base.Optional;
import com.hubspot.blazar.base.notifications.InstantMessageConfiguration;
import com.hubspot.rosetta.jdbi.BindWithRosetta;

public interface InstantMessageConfigurationDao {

  @SqlQuery("SELECT * FROM instant_message_configs WHERE active = 1")
  Set<InstantMessageConfiguration> getAll();

  @SingleValueResult
  @SqlQuery("SELECT * FROM instant_message_configs WHERE id = :id")
  Optional<InstantMessageConfiguration> get(@Bind("id") long id);

  @SqlQuery("SELECT * FROM instant_message_configs WHERE branchId = :branchId AND moduleId IS NULL AND active = 1")
  Set<InstantMessageConfiguration> getAllWithBranchId(@Bind("branchId") long branchId);

  @SqlQuery("SELECT * FROM instant_message_configs WHERE moduleId = :moduleId AND active = 1")
  Set<InstantMessageConfiguration> getAllWithModuleId(@Bind("moduleId") long moduleId);

  @GetGeneratedKeys
  @SqlUpdate("INSERT INTO instant_message_configs (branchId, moduleId, channelName, onFinish, onFail, onChange, onRecover, active) VALUES (:branchId, :moduleId, :channelName, :onFinish, :onFail, :onChange, :onRecover, :active)")
  long insert(@BindWithRosetta InstantMessageConfiguration instantMessageConfiguration);

  @SqlUpdate("INSERT INTO instant_message_configs (branchId, moduleId, channelName, onFinish, onFail, onChange, onRecover, active) VALUES (:branchId, :moduleId, :channelName, :onFinish, :onFail, :onChange, :onRecover, :active)")
  int update(@BindWithRosetta InstantMessageConfiguration instantMessageConfiguration);

  @SqlUpdate("UPDATE instant_message_configs SET active = 0 WHERE id = :id")
  int delete(@Bind("id") long id);

}

@@ -1532,35 +1532,30 @@
 @SqlUpdate(%22
-INSERT INTO
+UPDATE
  instant_mes
@@ -1571,184 +1571,336 @@
 igs 
-(branchId, moduleId, channelName, onFinish, onFail, onChange, onRecover, active) VALUES (:branchId, :moduleId, :channelName, :onFinish, :onFail, :onChange, :onRecover, :active)
+SET %22 +%0A          %22branchId = :branchId, %22 +%0A          %22moduleId = :moduleId, %22 +%0A          %22channelName = :channelName, %22 +%0A          %22onFinish = :onFinish, %22 +%0A          %22onFail = :onFail, %22 +%0A          %22onChange = :onChange, %22 +%0A          %22onRecover = :onRecover, %22 +%0A          %22active = :active %22 +%0A          %22WHERE id = :id
 %22)%0A 

fix this query