package io.reactivesw.catalog.inventory.application.controller;

import static io.reactivesw.route.InventoryEntryRouter.INVENTORY_ENTRY_ID;
import static io.reactivesw.route.InventoryEntryRouter.INVENTORY_ENTRY_ROOT;
import static io.reactivesw.route.InventoryEntryRouter.INVENTORY_ENTRY_WITH_ID;

import io.reactivesw.catalog.inventory.application.model.InventoryEntry;
import io.reactivesw.catalog.inventory.application.model.InventoryEntryDraft;
import io.reactivesw.catalog.inventory.domain.service.InventoryEntryService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Davis on 16/12/21.
 */
@RestController
public class InventoryEntryController {
  /**
   * log.
   */
  private static final Logger LOG = LoggerFactory.getLogger(InventoryEntryController.class);

  /**
   * The Inventory entry service.
   */
  @Autowired
  private transient InventoryEntryService inventoryEntryService;

  /**
   * Create inventory entry inventory entry.
   *
   * @param draft the draft
   * @return the inventory entry
   */
  @ApiOperation("Create InventoryEntry")
  @PostMapping(INVENTORY_ENTRY_ROOT)
  public InventoryEntry createInventoryEntry(InventoryEntryDraft draft) {
    LOG.debug("enter createInventoryEntry, inventory entry draft is : {}", draft.toString());

    InventoryEntry result = inventoryEntryService.createInventoryEntry(draft);

    LOG.debug("end createInventoryEntry, new InventoryEntry is : {}", result.toString());

    return result;
  }

  /**
   * Gets inventory entry by id.
   *
   * @param id the id
   * @return the inventory entry by id
   */
  @ApiOperation("get InventoryEntry by Id")
  @GetMapping(INVENTORY_ENTRY_WITH_ID)
  public InventoryEntry getInventoryEntryById(@PathVariable(value = INVENTORY_ENTRY_ID)
                                              @ApiParam(value = "InventoryEntry ID",
                                                  required = true)
                                                  String id) {
    LOG.debug("enter getInventoryEntryById, id is : {}", id);

    InventoryEntry result = inventoryEntryService.getInventoryEntryById(id);

    LOG.debug("end getInventoryEntryById, get result is : {}", result.toString());

    return result;
  }
}

@@ -724,16 +724,78 @@
 owired;%0A
+import org.springframework.web.bind.annotation.DeleteMapping;%0A
 import o
@@ -837,32 +837,32 @@
 ion.GetMapping;%0A
-
 import org.sprin
@@ -958,32 +958,92 @@
 on.PostMapping;%0A
+import org.springframework.web.bind.annotation.RequestBody;%0A
 import org.sprin
@@ -1568,17 +1568,17 @@
 ration(%22
-C
+c
 reate In
@@ -1961,32 +1961,32 @@
 t.toString());%0A%0A
-
     return resul
@@ -1993,16 +1993,864 @@
 t;%0A  %7D%0A%0A
+  /**%0A   * Delete inventory entry.%0A   *%0A   * @param id      the id%0A   * @param version the version%0A   */%0A  @ApiOperation(%22delete InventoryEntry%22)%0A  @DeleteMapping(INVENTORY_ENTRY_WITH_ID)%0A  public void deleteInventoryEntry(@PathVariable(value = INVENTORY_ENTRY_ID)%0A                                   @ApiParam(value = %22InventoryEntry Id%22, required = true)%0A                                       String id,%0A                                   @RequestBody%0A                                   @ApiParam(value = %22InventoryEntry Version%22, required = true)%0A                                       Integer version) %7B%0A    LOG.debug(%22enter deleteInventoryEntry, id is : %7B%7D, version is : %7B%7D%22, id, version);%0A%0A    inventoryEntryService.deleteInventoryEntry(id, version);%0A%0A    LOG.debug(%22end deleteInventoryEntry, id is : %7B%7D, version is : %7B%7D%22, id, version);%0A  %7D%0A%0A
   /**%0A  

add delete function to inventoryentry controller