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

import com.hys.app.framework.context.user.AdminUserContext;
import com.hys.app.framework.database.WebPage;
import com.hys.app.model.erp.dos.SaleChannelDO;
import com.hys.app.model.erp.dto.OrderDTO;
import com.hys.app.model.erp.dto.OrderQueryParams;
import com.hys.app.model.erp.dto.SaleChannelQueryParams;
import com.hys.app.model.erp.vo.OrderVO;
import com.hys.app.model.erp.vo.SaleChannelV0;
import com.hys.app.model.support.LogClient;
import com.hys.app.model.support.validator.annotation.Log;
import com.hys.app.service.erp.OrderManager;
import com.hys.app.service.erp.SaleChannelManager;
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/sale/channel")
@Api(tags = "销售渠道相关api")
@Validated
public class SaleChannelController {

    @Autowired
    private SaleChannelManager saleChannelManager;

    @ApiOperation(value = "分页列表")
    @GetMapping
    public WebPage<SaleChannelV0> list(SaleChannelQueryParams queryParams) {
        return saleChannelManager.list(queryParams);
    }

    @ApiOperation(value = "添加")
    @PostMapping
    @Log(client = LogClient.admin, detail = "创建名称为[${request.name}]的渠道")
    public void add(@RequestBody @Valid SaleChannelDO request) {
        AdminUserContext.hasCompany();
        saleChannelManager.add(request);
    }

    @ApiOperation(value = "修改")
    @PutMapping("/{id}")
    @Log(client = LogClient.admin, detail = "修改id为[${id}]的渠道")
    public void edit(@PathVariable Long id, @RequestBody @Valid SaleChannelDO request) {
        saleChannelManager.edit(request,id);
    }

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

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


}

