package com.trade.client.salesorder.controller;

import com.github.pagehelper.PageInfo;
import com.trade.service.salesorder.dto.SalesOrderDTO;
import com.trade.service.salesorder.dto.SalesOrderDeliverDTO;
import com.trade.client.salesorder.service.SalesOrderCService;
import com.trade.common.core.domain.ResponseResult;
import com.trade.service.salesorder.vo.SalesOrderDtlVO;
import com.trade.service.salesorder.vo.SalesOrderSearch;
import com.trade.service.salesorder.vo.SalesOrderVO;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 销售订单表 C端控制器
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-06
 */
@Controller
@RequestMapping("/salesOrder")
public class SalesOrderController {

    @Resource
    private SalesOrderCService salesOrderCService;

    /**
     * 销售订单-list
     */
    @RequestMapping("/list")
    public ResponseResult<PageInfo<SalesOrderVO>> list(SalesOrderSearch search) {
        return ResponseResult.success(salesOrderCService.queryListBySearch(search));
    }

    /**
     * 销售订单-保存
     */
    @RequestMapping("/save")
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResponseResult<Void> add(SalesOrderDTO salesOrderDTO) {
        salesOrderCService.save(salesOrderDTO, false);
        return ResponseResult.success();
    }

    /**
     * 销售订单-提交
     */
    @RequestMapping("/submit")
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResponseResult<Void> submit(@RequestBody @Valid SalesOrderDTO salesOrderDTO) {
        salesOrderCService.submit(salesOrderDTO);
        return ResponseResult.success();
    }

    /**
     * 销售订单-发货
     */
    @RequestMapping("/deliver")
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResponseResult<Void> deliver(@RequestBody @Valid SalesOrderDeliverDTO orderDeliverDTO) {
        salesOrderCService.deliver(orderDeliverDTO);
        return ResponseResult.success();
    }

    /**
     * 销售订单-详情
     * 
     * @param id 销售订单ID
     * @param is4Update 是否为更新
     */
    @RequestMapping("/detail")
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResponseResult<SalesOrderDtlVO> detail(Long id, Boolean is4Update) {
        return ResponseResult.success(salesOrderCService.getDetail(id, is4Update));
    }

    /**
     * 销售订单-删除
     */
    @RequestMapping("/delete")
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResponseResult<Boolean> delete(Long id) {
        return ResponseResult.success(salesOrderCService.delete(id));
    }
}
