package com.crm.pay.controller;

import com.crm.pay.service.CustomFundHistoryService;
import com.crm.rely.backend.core.constant.FeignClientAnnotation;
import com.crm.rely.backend.core.constant.PrefixEnum;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.model.entity.user.info.UserInfoEntity;
import com.crm.rely.backend.model.dto.custom.fund.history.CustomFundHistoryDto;
import com.crm.rely.backend.model.entity.custom.fund.history.CustomFundHistorySearchListEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;


@RestController
@RequestMapping("/custom/fund/history")
public class CustomFundHistoryController {

    @Autowired
    private CustomFundHistoryService service;

    @PostMapping("/manager/search/list")
    @FeignClientAnnotation
    public ResultWithPagerDto<CustomFundHistoryDto> searchList(@RequestBody @Validated CustomFundHistorySearchListEntity entity, UserInfoEntity infoEntity) throws Exception {

        if (PrefixEnum.PREFIX_SALE.equals(infoEntity.getPrefix())) {
            entity.setStamp(infoEntity.getStamp());
        } else {
            entity.setStamp(null);
        }
        ResultWithPagerDto<CustomFundHistoryDto> resultWithPagerDto = service.searchPageList(entity);
        return resultWithPagerDto;
    }

}