package com.neusoft.smart.pos.inventory.controller;

import com.neusoft.smart.pos.framework.dto.ResponseData;
import com.neusoft.smart.pos.dto.inventory.request.GetSupplierRequest;
import com.neusoft.smart.pos.dto.inventory.request.PostSupplierRequest;
import com.neusoft.smart.pos.dto.inventory.response.SupplierResponse;
import com.neusoft.smart.pos.inventory.service.SupplierService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(value = "供应商管理使用rest接口", description = "供应商管理使用rest接口")
@RequestMapping(path = "/inventory/supplier")
@Validated
public class SupplierController {
    
    @Autowired
    SupplierService supplierService;
    
    @ApiOperation(value = "供应商查询列表接口")
    @GetMapping("/list")
    public ResponseData<List<SupplierResponse>> getList(GetSupplierRequest request) {
        return new ResponseData<>(supplierService.getList(request));
    }
    
    
    @ApiOperation(value = "供应商查询接口")
    @GetMapping("/{id}")
    public ResponseData<SupplierResponse> detail(@PathVariable Integer id) {
        return new ResponseData<>(supplierService.getDetail(id));
    }
    
    @ApiOperation(value = "创建供应商接口")
    @PostMapping("/")
    public ResponseData<SupplierResponse> create(@RequestBody PostSupplierRequest request) {
        return new ResponseData<>(supplierService.create(request));
    }
    
    @ApiOperation(value = "修改供应商接口")
    @PutMapping("/")
    public ResponseData<Integer> update(@RequestBody PostSupplierRequest request) {
        supplierService.update(request);
        return new ResponseData<>(1);
    }
    
    @ApiOperation(value = "删除供应商接口")
    @DeleteMapping("/{id}")
    public ResponseData<Integer> delete(@PathVariable Integer id) {
        supplierService.delete(id);
        return new ResponseData<>(1);
    }
}
