package com.crm.pay.controller;

import com.crm.pay.service.SysRemitChannelService;
import com.crm.rely.backend.core.constant.Constants;
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.entity.base.SingleLongEntity;
import com.crm.rely.backend.model.dto.sys.remit.SysRemitChannelDto;
import com.crm.rely.backend.model.dto.sys.remit.SysRemitChannelGetCodeDto;
import com.crm.rely.backend.model.entity.sys.remit.SysRemitChannelBatchUpdateEntity;
import com.crm.rely.backend.model.entity.sys.remit.SysRemitChannelByCodeEntity;
import com.crm.rely.backend.model.entity.sys.remit.SysRemitChannelListEntity;
import com.crm.rely.backend.model.entity.sys.remit.SysRemitChannelSearchEntity;
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;


/**
 * 出金通道信息
 */
@RestController
@RequestMapping("/remit/channel")
public class SysRemitChannelController {

    @Autowired
    private SysRemitChannelService sysRemitChannelService;

    @PostMapping("/list")
    public BaseResultDto<List<SysRemitChannelDto>> selectList(@RequestBody @Validated SysRemitChannelListEntity entity) throws Exception {

        return sysRemitChannelService.getAllList(entity);
    }

    /**
     * 根据code 获取通道信息
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/code")
    public BaseResultDto<SysRemitChannelDto> getByCode(@RequestBody @Validated SysRemitChannelByCodeEntity entity) throws Exception {

        return sysRemitChannelService.get(entity);
    }

    @PostMapping("/manager/get/code")
    @FeignClientAnnotation
    public BaseResultDto<List<SysRemitChannelGetCodeDto>> getCodeList() throws Exception {


        List<SysRemitChannelGetCodeDto> codeList = sysRemitChannelService.getCodeList();

        return BaseResultDto.success(codeList);
    }

    @PostMapping("/manager/batch/update")
    @FeignClientAnnotation
    public BaseResultDto updateBatch(@RequestBody @Validated SysRemitChannelBatchUpdateEntity entity) throws Exception {
        if (entity == null) {
            return BaseResultDto.error(Constants.SYSTEM_ERROR);
        }

        sysRemitChannelService.save(entity, entity.getData());
        return BaseResultDto.success();
    }

    /**
     * 列表出金通道
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/manager/search/list")
    @FeignClientAnnotation
    public ResultWithPagerDto<SysRemitChannelDto> searchList(@RequestBody @Validated SysRemitChannelSearchEntity entity) throws Exception {


        ResultWithPagerDto<SysRemitChannelDto> result = sysRemitChannelService.searchPageList(entity);

        return result;
    }

    @PostMapping("/manager/list")
    @FeignClientAnnotation
    public BaseResultDto list() throws Exception {

        List<SysRemitChannelDto> result = sysRemitChannelService.searchList();

        return BaseResultDto.success(result);
    }

    /**
     * 单个查询
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/manager/search/single")
    @FeignClientAnnotation
    public BaseResultDto single(@RequestBody @Validated SingleLongEntity entity) throws Exception {

        SysRemitChannelDto result = sysRemitChannelService.searchSingle(entity);

        return BaseResultDto.success(result);
    }


}
