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

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.crm.dal.dataobject.crmcontract.CrmContractProductDO;
import cn.iocoder.yudao.module.crm.service.crmcontract.CrmContractService;
import cn.iocoder.yudao.module.hrm.api.crmcontract.ContractApi;
import cn.iocoder.yudao.module.hrm.api.crmcontract.dto.CrmContractProductDTO;
import cn.iocoder.yudao.module.hrm.api.crmcontract.dto.CrmContractProductSettlementDTO;
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 ContractApiImpl implements ContractApi {

    @Resource
    private CrmContractService crmContractService;

    @Override
    public CommonResult<Boolean> createProduct(List<CrmContractProductDTO> createReqVO) {

        crmContractService.createProduct(BeanUtils.toBean(createReqVO, CrmContractProductDO.class));
        return success(true);
    }

    @Override
    public CommonResult<List<CrmContractProductDTO>> getProduct(Long contractId) {
        List<CrmContractProductDO> contractProductDOS = crmContractService.getContractProductListByContractId(contractId);
        return success(BeanUtils.toBean(contractProductDOS, CrmContractProductDTO.class));
    }
}
