package com.crm.custom.controller;

import com.crm.custom.service.CustomRecommendService;
import com.crm.login.rely.backend.controller.BaseLoginController;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.model.dto.custom.CustomInfoLoginDto;
import com.crm.rely.backend.model.dto.custom.CustomInfoRecommendDto;
import com.crm.rely.backend.model.entity.custom.CustomInfoListEntity;
import com.crm.rely.backend.model.entity.custom.CustomInfoLoginListEntity;
import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
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("/recommend")
public class CustomRecommendController extends BaseLoginController {
    @Autowired
    private CustomRecommendService service;

    @PostMapping("/search/list")
    public BaseResultDto searchPageList(@RequestBody @Validated CustomInfoLoginListEntity entity, CustomInfoEntity infoEntity) throws Exception {
        if (infoEntity.getIbId() == null) {
            return BaseResultDto.error(Constants.NOT_PERMIT);
        }
        entity.setAgentId(infoEntity.getIbId());
        ResultWithPagerDto<CustomInfoLoginDto> result = service.searchPageList(entity);

        return result;
    }

    @PostMapping("/real/search/list")
    public BaseResultDto searchPageList(@RequestBody @Validated CustomInfoListEntity entity, CustomInfoEntity infoEntity) throws Exception {
        if (infoEntity.getIbId() == null) {
            return BaseResultDto.error(Constants.NOT_PERMIT);
        }
        entity.setAgentId(infoEntity.getIbId());
        ResultWithPagerDto<CustomInfoRecommendDto> result = service.searchPageList(entity);

        return result;
    }
}
