package com.crm.manager.controller;

import com.crm.manager.service.CooperativePartnerService;
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.cooperative.partner.agent.CooperativePartnerAgentDto;
import com.crm.rely.backend.core.dto.cooperative.partner.subset.CooperativePartnerSubsetDto;
import com.crm.rely.backend.core.dto.cooperative.partner.us.CooperativePartnerUsDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.cooperative.partner.agent.*;
import com.crm.rely.backend.core.entity.cooperative.partner.subset.*;
import com.crm.rely.backend.core.entity.cooperative.partner.us.*;
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("/cooperative/partner")
public class CooperativePartnerController {

    @Autowired
    private CooperativePartnerService cooperativePartnerService;

    @PostMapping("/agent/add")
    public BaseResultDto addAgent(@RequestBody @Validated CooperativePartnerAgentAddEntity entity) throws Exception {
        entity.setType(1);
        cooperativePartnerService.addAgent(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/agent/update")
    public BaseResultDto updateAgent(@RequestBody @Validated CooperativePartnerAgentUpdateEntity entity) throws Exception {

        cooperativePartnerService.updateAgent(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/agent/approve")
    public BaseResultDto approveAgent(@RequestBody @Validated CooperativePartnerAgentApproveEntity entity) throws Exception {

        cooperativePartnerService.approveAgent(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/agent/delete")
    public BaseResultDto deleteAgent(@RequestBody @Validated CooperativePartnerAgentDeleteEntity entity) throws Exception {

        cooperativePartnerService.deleteAgent(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/agent/search/list")
    public ResultWithPagerDto<CooperativePartnerAgentDto> searchAgentList(@RequestBody @Validated CooperativePartnerAgentSearchEntity entity) throws Exception {

        entity.setType(1);
        return cooperativePartnerService.searchAgentPageList(entity);
    }

    @PostMapping("/agent/search/single")
    public BaseResultDto<CooperativePartnerAgentDto> searchAgentSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        CooperativePartnerAgentDto dto = cooperativePartnerService.searchAgentSingle(entity);
        return BaseResultDto.success(dto);
    }

    @PostMapping("/subset/add")
    public BaseResultDto addSubset(@RequestBody @Validated CooperativePartnerSubsetAddEntity entity) throws Exception {
        entity.setType(2);
        cooperativePartnerService.addSubset(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/subset/update")
    public BaseResultDto updateSubset(@RequestBody @Validated CooperativePartnerSubsetUpdateEntity entity) throws Exception {

        cooperativePartnerService.updateSubset(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/subset/approve")
    public BaseResultDto approveSubset(@RequestBody @Validated CooperativePartnerSubsetApproveEntity entity) throws Exception {

        cooperativePartnerService.approveSubset(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/subset/delete")
    public BaseResultDto deleteSubset(@RequestBody @Validated CooperativePartnerSubsetDeleteEntity entity) throws Exception {

        cooperativePartnerService.deleteSubset(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/subset/search/list")
    public ResultWithPagerDto<CooperativePartnerSubsetDto> searchSubsetList(@RequestBody @Validated CooperativePartnerSubsetSearchEntity entity) throws Exception {
        entity.setType(2);
        return cooperativePartnerService.searchSubsetPageList(entity);
    }

    @PostMapping("/subset/search/single")
    public BaseResultDto<CooperativePartnerSubsetDto> searchSubsetSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        CooperativePartnerSubsetDto dto = cooperativePartnerService.searchSubsetSingle(entity);
        return BaseResultDto.success(dto);
    }

    @PostMapping("/us/add")
    public BaseResultDto addUs(@RequestBody @Validated CooperativePartnerUsAddEntity entity) throws Exception {
        entity.setType(3);
        cooperativePartnerService.addUs(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/us/update")
    public BaseResultDto updateUs(@RequestBody @Validated CooperativePartnerUsUpdateEntity entity) throws Exception {

        cooperativePartnerService.updateUs(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/us/approve")
    public BaseResultDto approveUs(@RequestBody @Validated CooperativePartnerUsApproveEntity entity) throws Exception {

        cooperativePartnerService.approveUs(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/us/delete")
    public BaseResultDto deleteUs(@RequestBody @Validated CooperativePartnerUsDeleteEntity entity) throws Exception {

        cooperativePartnerService.deleteUs(entity);
        return BaseResultDto.success();
    }

    @PostMapping("/us/search/list")
    public ResultWithPagerDto<CooperativePartnerUsDto> searchUsList(@RequestBody @Validated CooperativePartnerUsSearchEntity entity) throws Exception {

        entity.setType(3);
        return cooperativePartnerService.searchUsPageList(entity);
    }

    @PostMapping("/us/search/single")
    public BaseResultDto<CooperativePartnerUsDto> searchUsSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {
        CooperativePartnerUsDto dto = cooperativePartnerService.searchUsSingle(entity);
        return BaseResultDto.success(dto);
    }

}
