package com.hys.app.controller.erp.use;

import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dto.CustomerDTO;
import com.hys.app.model.erp.dto.CustomerQueryParams;
import com.hys.app.model.erp.dto.OrderDTO;
import com.hys.app.model.erp.dto.OrderQueryParams;
import com.hys.app.model.erp.vo.CustomerVO;
import com.hys.app.model.erp.vo.OrderVO;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.service.erp.CustomerManager;
import com.hys.app.service.erp.OrderManager;
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.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 订单 API
 *
 * @author 张崧
 * 2024-01-24 15:58:31
 */
@RestController
@RequestMapping("/admin/erp/customer")
@Api(tags = "客户相关接口")
@Validated
public class CustomerController {

    @Autowired
    private CustomerManager customerManager;

    @ApiOperation(value = "分页列表")
    @GetMapping
    public WebPage<CustomerVO> list(CustomerQueryParams queryParams) {
        return customerManager.list(queryParams);
    }

    @ApiOperation(value = "添加")
    @PostMapping
    @Log(client = LogClient.admin, detail = "创建订单")
    public void add(@RequestBody @Valid CustomerDTO customerDTO) {
        customerManager.add(customerDTO);
    }

    @ApiOperation(value = "修改")
    @PutMapping("/{id}")
    @Log(client = LogClient.admin, detail = "修改id为[${id}]的订单")
    public void edit(@PathVariable Long id, @RequestBody @Valid CustomerDTO customerDTO) {
        customerDTO.setId(id);
        customerManager.edit(customerDTO);
    }

    @ApiOperation(value = "查询")
    @GetMapping("/{id}")
    public CustomerVO getDetail(@PathVariable Long id) {
        return customerManager.getDetail(id);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/{id}")
    @Log(client = LogClient.admin, detail = "删除id为[${id}]的订单")
    public void delete(@PathVariable Long id) {
        customerManager.delete(id);
    }

}

