package com.crm.manager.controller;

import com.crm.manager.service.MarketAgentLinkService;
import com.crm.rely.backend.core.constant.FeignClientAnnotation;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
import com.crm.rely.backend.core.dto.market.agnet.link.MarketAgentLinkDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.market.agent.link.MarketAgentLinkAddEntity;
import com.crm.rely.backend.core.entity.market.agent.link.MarketAgentLinkDeleteEntity;
import com.crm.rely.backend.core.entity.market.agent.link.MarketAgentLinkSearchPageEntity;
import com.crm.rely.backend.core.entity.market.agent.link.MarketAgentLinkUpdateEntity;
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;

import java.util.List;

/**
 * @author: houn
 */
@RestController
@RequestMapping("/market/agent/link")
public class MarketAgentLinkController {

    @Autowired
    private MarketAgentLinkService marketExtensionService;

    /**
     * 添加
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated MarketAgentLinkAddEntity entity) throws Exception {
        marketExtensionService.add(entity);
        return BaseResultDto.success();


    }

    /**
     * 删除
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated MarketAgentLinkDeleteEntity entity) throws Exception {
        marketExtensionService.delete(entity);

        return BaseResultDto.success();
    }

    /**
     * 修改
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated MarketAgentLinkUpdateEntity entity) throws Exception {
        marketExtensionService.update(entity);

        return BaseResultDto.success();
    }

    /**
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/list")
    public BaseResultDto pageList(@RequestBody @Validated MarketAgentLinkSearchPageEntity entity) throws Exception {

        ResultWithPagerDto<MarketAgentLinkDto>
                dto = marketExtensionService.pageSearchList(entity);

        return dto;
    }


    @PostMapping("/search/single")
    public BaseResultDto single(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        MarketAgentLinkDto marketExtensionDto = marketExtensionService.searchSingle(entity.getId());

        return BaseResultDto.success(marketExtensionDto);
    }


    @PostMapping("/ib/list")
    @FeignClientAnnotation
    public BaseResultDto list(@RequestBody MarketAgentLinkSearchPageEntity entity) throws Exception {
        entity.setPage(null);
        List<MarketAgentLinkDto>
                dto = marketExtensionService.searchList(entity);

        return BaseResultDto.success(dto);
    }
}
