package com.crm.manager.controller;

import com.crm.manager.service.AccountBelongChangeService;
import com.crm.rely.backend.core.constant.FeignClientAnnotation;
import com.crm.rely.backend.core.dto.account.belong.AccountBelongChangeDto;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.BaseResultWithPagerDto;
import com.crm.rely.backend.core.entity.account.belong.AccountBelongChangeAddEntity;
import com.crm.rely.backend.core.entity.account.belong.AccountBelongChangeListEntity;
import com.crm.rely.backend.core.entity.base.BaseApproveEntity;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.custom.info.CustomInfoUpdateAgentEntity;
import com.crm.rely.backend.core.entity.custom.info.InfoEntity;
import com.google.common.collect.Lists;
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;

/**
 * Created by max on 2020/8/4.
 */
@RestController
@RequestMapping("/account/belong/change")
public class AccountBelongChangeController {

    @Autowired
    private AccountBelongChangeService accountBelongChangeService;


    @PostMapping("/search/list")
    BaseResultWithPagerDto<List<AccountBelongChangeDto>> searchList(@RequestBody AccountBelongChangeListEntity entity, InfoEntity infoEntity) throws Exception {
        return accountBelongChangeService.searchList(entity);
    }

    @PostMapping("/search/single")
    public BaseResultDto<AccountBelongChangeDto> searchSingle(@RequestBody SingleLongEntity entity, InfoEntity infoEntity) throws Exception {

        return accountBelongChangeService.searchSingle(entity);
    }

    @PostMapping("/approve")
    public BaseResultDto<Object> approve(@RequestBody BaseApproveEntity entity, InfoEntity infoEntity) throws Exception {
        return accountBelongChangeService.approve(entity);
    }

    @PostMapping("/add")
    public BaseResultDto<Object> add(@RequestBody AccountBelongChangeAddEntity entity, InfoEntity infoEntity) throws Exception {
        return accountBelongChangeService.add(entity);
    }

    @PostMapping("/batch/add")
    public BaseResultDto<List<BaseResultDto>> batchAdd(@RequestBody List<AccountBelongChangeAddEntity> entities, InfoEntity infoEntity) throws Exception {
        BaseResultDto<List<BaseResultDto>> resultDto = BaseResultDto.success();
        resultDto.setData(Lists.newArrayList());
        for (AccountBelongChangeAddEntity entity : entities) {
            resultDto.getData().add(accountBelongChangeService.add(entity));
        }
        return resultDto;
    }


}
