package com.gree.mall.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.manager.exception.RemoteServiceException;
import com.gree.mall.manager.helper.ResponseHelper;
import com.gree.mall.manager.logic.StorageLogic;
import com.gree.mall.manager.plus.entity.Storage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@Api(value = "仓储管理", tags ={"仓储管理"} )
@RequestMapping(value = "/storage", produces = "application/json; charset=utf-8")
public class StorageController {

    @Resource
    StorageLogic storageLogic;

    @GetMapping("/list")
    @ApiOperation(value = "仓储列表")
    public ResponseHelper<Page<Storage>> page(
            @ApiParam(value = "页号",required = true) @RequestParam Integer pageNum,
            @ApiParam(value = "页大小",required = true) @RequestParam Integer pageSize,
            HttpServletRequest request
    ) throws RemoteServiceException {
        IPage<Storage> page = storageLogic.page(pageNum, pageSize,request);
        return ResponseHelper.success(page);
    }

    @GetMapping("/detail")
    @ApiOperation(value = "仓储详情")
    public ResponseHelper<Storage> detail(
            @ApiParam(value = "id",required = true) @RequestParam() String id
    ) throws RemoteServiceException {
        Storage detail = storageLogic.detail(id);
        return ResponseHelper.success(detail);
    }


    @PostMapping("/add")
    @ApiOperation(value = "新增仓储")
    public ResponseHelper add(
            HttpServletRequest request,
            @ApiParam(value = "object",required = true) @RequestBody Storage storage) {
        storageLogic.add(request,storage);
        return ResponseHelper.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改仓储")
    public ResponseHelper update(
            @ApiParam(value = "object",required = true) @RequestBody Storage storage) {
        storageLogic.update(storage);
        return ResponseHelper.success();
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除仓储")
    public ResponseHelper delete(
            @ApiParam(value = "仓储id",required = true) @RequestParam String storageId
    ) {
        storageLogic.delete(storageId);
        return ResponseHelper.success();
    }

}
