package com.storlead.sales.controller.customer;


import com.storlead.framework.common.result.Result;
import com.storlead.sales.pojo.dto.customer.CustomerFollowUpAddDTO;
import com.storlead.sales.pojo.dto.customer.CustomerFollowUpSearchDTO;
import com.storlead.sales.pojo.vo.customer.CustomerFollowUpDetailVO;
import com.storlead.sales.pojo.vo.customer.CustomerFollowUpListVO;
import com.storlead.sales.service.customer.CustomerFollowUpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * <p>
 * 客户跟进记录表 前端控制器
 * </p>
 *
 * @author YPZ
 * @since 2024-04-19
 */
@RestController
@RequestMapping("/customer-follow-up")
@Api(tags = "销售: 客户管理相关接口")
public class CustomerFollowUpController {

    @Resource
    private CustomerFollowUpService customerFollowUpService;


    @PostMapping(value = "/add")
    @ApiOperation(value = "客户跟进记录管理-新增/修改客户跟进记录", notes = "客户跟进记录管理-新增/修改客户跟进记录")
    @Transactional(rollbackFor = Throwable.class)
    public Result<?> add(@RequestBody CustomerFollowUpAddDTO customerFollowUpAddDTO) {
        return customerFollowUpService.addCustomerFollowUp(customerFollowUpAddDTO);

    }

    @PostMapping(value = "/list")
    @ApiOperation(value = "客户跟进记录查询-列表", notes = "客户跟进记录查询-列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "", response = CustomerFollowUpListVO.class)
    })
    public Result<?> list(@RequestBody CustomerFollowUpSearchDTO customerFollowUpSearchDTO) {

        return customerFollowUpService.selectListVO(customerFollowUpSearchDTO);
    }

    @GetMapping(value = "/get-by-id")
    @ApiOperation(value = "客户跟进记录查询-通过id查看详情", notes = "客户跟进记录查询-通过id查看详情")
    public Result<CustomerFollowUpDetailVO> getById(@RequestParam(name="id",required=false) Long id) {
        CustomerFollowUpDetailVO customerFollowUpDetailVO = customerFollowUpService.getVOById(id);
        return Result.result(customerFollowUpDetailVO);
    }

    @ApiOperation(value = "客户跟进记录管理-删除客户跟进记录", notes = "客户跟进记录管理-删除客户跟进记录")
    @PostMapping("delete")
    public Result delete(Long id) {
        if(Objects.isNull(id)) {
            return Result.error("参数错误");
        }
        customerFollowUpService.lgDelete(id);
        return Result.ok();
    }
}
