package com.crm.manager.controller;

import com.crm.manager.service.SalesDpsSalaryRecordService;
import com.crm.rely.backend.core.constant.PrefixEnum;
import com.crm.rely.backend.core.dto.base.BaseReportResultDto;
import com.crm.rely.backend.core.dto.sales.SalesDpsSalaryRecordDto;
import com.crm.rely.backend.core.dto.sales.SalesDpsSalaryRecordSumDto;
import com.crm.rely.backend.core.entity.base.BaseIbReportListEntity;
import com.crm.rely.backend.core.entity.custom.info.InfoEntity;
import com.crm.rely.backend.core.entity.sales.SalesDpsSalaryRecordListEntity;
import com.crm.rely.backend.exception.ServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sales/dps/salary/record")
public class SalesDpsSalaryRecordController {

    @Autowired
    private SalesDpsSalaryRecordService salesDpsSalaryRecordService;

    @PostMapping("/search/list")
    public BaseReportResultDto<List<SalesDpsSalaryRecordDto>, SalesDpsSalaryRecordSumDto> searchList(@RequestBody BaseIbReportListEntity entity, InfoEntity infoEntity) throws ServiceException {

        if (PrefixEnum.PREFIX_SALE.equals(infoEntity.getPrefix())) {
            entity.setSalesId(infoEntity.getIbInfo().getId());
        }

        return salesDpsSalaryRecordService.searchList(entity);
    }

}
