package cn.iocoder.yudao.module.crm.api.crmbusiness;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.controller.admin.crmbusiness.vo.CrmBusinessRespVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.crmbusiness.CrmBusinessProductDO;
import cn.iocoder.yudao.module.crm.service.crmbusiness.CrmBusinessService;
import cn.iocoder.yudao.module.hrm.api.crmbusiness.BusinessApi;
import cn.iocoder.yudao.module.hrm.api.crmbusiness.dto.CrmBusinessDTO;
import cn.iocoder.yudao.module.hrm.api.crmbusiness.dto.CrmBusinessProductDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * Flowable CRM Api 实现类
 */
@RestController
@Validated
public class BusinessApiImpl implements BusinessApi {

    @Resource
    private CrmBusinessService businessService;

    @Override
    public CommonResult<CrmBusinessDTO> getBusiness(Long id) {
        CrmBusinessRespVO businessDO = businessService.getBusiness(id);
        return success(BeanUtils.toBean(businessDO, CrmBusinessDTO.class));
    }

    @Override
    public CommonResult<List<CrmBusinessProductDTO>> getBusinessProduct(Long businessId) {
        List<CrmBusinessProductDO> businessProductList = businessService.getBusinessProductListByBusinessId(businessId);
        return success(BeanUtils.toBean(businessProductList, CrmBusinessProductDTO.class));
    }

    @Override
    public CommonResult<Boolean> updateIsEnd(Long id, Integer isEnd) {
        businessService.updateIsEnd(id, isEnd);
        return success(true);
    }
}
