semantics :: Bug -> Command Concrete -> ReaderT ConnectInfo IO (Response Concrete)
semantics bug cmd = do
  connInfo <- ask
  liftIO $ withConnection connInfo $ \cn -> case cmd of
    NewBook _ (Isbn key) t a  -> toResp insertRes <$> addBook key t a cn
    AddCopy _ (Isbn key)      -> toResp updateRes <$> addCopy key cn
    Borrow  _ (Isbn key)      -> toResp updateRes <$> borrowCopy key cn
    Return  _ (Isbn key)      -> toResp updateRes <$> returnCopy bug key cn
    FindByAuthor _ x          -> toResp Rows <$> findByAuthor bug x cn
    FindByTitle  _ x          -> toResp Rows <$> findByTitle bug x cn
    FindByIsbn   _ (Isbn key) -> toResp Rows <$> findByIsbn key cn
  where toResp = maybe UniqueError
        updateRes 0 = NotFound
        updateRes 1 = Updated
        updateRes _ = OtherError
        insertRes 1 = Inserted
        insertRes _ = OtherError

-- Mock is currently not used by the library
semantics :: Bug -> Command Concrete -> ReaderT ConnectInfo IO (Response Concrete)
semantics bug cmd = do
  connInfo <- ask
  liftIO $ withConnection connInfo $ \cn -> case cmd of
    NewBook _ (Isbn key) t a  -> toResp insertRes <$> addBook key t a cn
    AddCopy _ (Isbn key)      -> toResp updateRes <$> addCopy key cn
    Borrow  _ (Isbn key)      -> toResp updateRes <$> borrowCopy key cn
    Return  _ (Isbn key)      -> toResp updateRes <$> returnCopy bug key cn
    FindByAuthor _ x          -> toResp Rows <$> findByAuthor bug x cn
    FindByTitle  _ x          -> toResp Rows <$> findByTitle bug x cn
    FindByIsbn   _ (Isbn key) -> toResp Rows <$> findByIsbn key cn
  where toResp = maybe UniqueError
        updateRes 0 = NotFound
        updateRes 1 = Updated
        updateRes _ = OtherError
        insertRes 1 = Inserted
        insertRes _ = OtherError

-- Mock is currently not used by the library
semantics bug cmd = do
  connInfo <- ask
  liftIO $ withConnection connInfo $ \cn -> case cmd of
    NewBook _ (Isbn key) t a  -> toResp insertRes <$> addBook key t a cn
    AddCopy _ (Isbn key)      -> toResp updateRes <$> addCopy key cn
    Borrow  _ (Isbn key)      -> toResp updateRes <$> borrowCopy key cn
    Return  _ (Isbn key)      -> toResp updateRes <$> returnCopy bug key cn
    FindByAuthor _ x          -> toResp Rows <$> findByAuthor bug x cn
    FindByTitle  _ x          -> toResp Rows <$> findByTitle bug x cn
    FindByIsbn   _ (Isbn key) -> toResp Rows <$> findByIsbn key cn
  where toResp = maybe UniqueError
        updateRes 0 = NotFound
        updateRes 1 = Updated
        updateRes _ = OtherError
        insertRes 1 = Inserted
        insertRes _ = OtherError

-- Mock is currently not used by the library