package com.crm.manager.controller;

import com.crm.manager.service.CommonService;
import com.crm.manager.service.finance.SysRemittanceChannelFeignService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import com.crm.rely.backend.core.entity.base.SingleLongEntity;
import com.crm.rely.backend.core.entity.system.remittance.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 配置入金通道
 *
 * @author houn
 */
@RestController
@RequestMapping("/remittance/channel")
public class SysRemittanceChannelController {

    @Autowired
    private SysRemittanceChannelFeignService sysRemittanceChannelFeignService;

    @Autowired
    private CommonService commonService;

    /**
     * 添加入金通道
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    public BaseResultDto add(@RequestBody @Validated SysRemittanceChannelAddEntity entity) throws Exception {
        return sysRemittanceChannelFeignService.add(entity);
    }

    /**
     * 删除入金通道
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/delete")
    public BaseResultDto delete(@RequestBody @Validated SysRemittanceChannelDeleteEntity entity) throws Exception {

        return sysRemittanceChannelFeignService.delete(entity);
    }

    /**
     * 修改入金通道
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    public BaseResultDto update(@RequestBody @Validated SysRemittanceChannelUpdateEntity entity) throws Exception {

        return sysRemittanceChannelFeignService.update(entity);
    }

    @PostMapping("/batch/update")
    public BaseResultDto updateBatch(@RequestBody @Validated SysRemittanceChannelBatchUpdateEntity entity) throws Exception {

        return sysRemittanceChannelFeignService.updateBatch(entity);
    }

    /**
     * 列表入金通道
     *
     * @param entity
     * @return
     * @throws Exception
     */
    @PostMapping("/search/list")
    public BaseResultDto searchList(@RequestBody @Validated SysRemittanceChannelSearchEntity entity) throws Exception {


        return sysRemittanceChannelFeignService.searchList(entity);
    }

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

        return sysRemittanceChannelFeignService.list();
    }

    @PostMapping("/get/code")
    public BaseResultDto getCodeList() throws Exception {

        return sysRemittanceChannelFeignService.getCodeList();
    }

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

        return sysRemittanceChannelFeignService.single(entity);
    }

    @PostMapping("/{method}/upload")
    public BaseResultDto upload(@PathVariable("method") String method, @RequestParam(value = "file", required = false) MultipartFile file) throws Exception {

        if (!"add".equals(method) && !"update".equals(method)) {
            return BaseResultDto.error(Constants.SYSTEM_ERROR);
        }
        String middlePath = "/channel/remittance";
        commonService.validated(file);
        String path = commonService.uploadFile(middlePath, file);

        return BaseResultDto.success(Constants.UPLOAD_SUCCESS, path);
    }

    @PostMapping("/get/custom/remittance/tick")
    public BaseResultDto getCustomRemittanceTick(@RequestBody SysRemittanceChannelByCIdEntity entity) throws Exception {
        return sysRemittanceChannelFeignService.getCustomRemittanceTick(entity);

    }

    @PostMapping("/update/custom/remittance/tick")
    public BaseResultDto updateCustomRemittanceTick(@RequestBody SysRemittanceChannelUpdateCustomByCIdEntity entity) throws Exception {
        return sysRemittanceChannelFeignService.updateCustomRemittanceTick(entity);
    }

    @PostMapping("/add/send/code")
    public BaseResultDto addChannelSendEmailCode() throws Exception {

        return sysRemittanceChannelFeignService.addChannelSendEmailCode();
    }

    @PostMapping("/batch/update/send/code")
    public BaseResultDto updateChannelBatchSendEmailCode() throws Exception {

        return sysRemittanceChannelFeignService.updateChannelBatchSendEmailCode();
    }

    @PostMapping("/update/send/code")
    public BaseResultDto updateChannelSendEmailCode() throws Exception {

        return sysRemittanceChannelFeignService.updateChannelSendEmailCode();
    }

    @PostMapping("/delete/send/code")
    public BaseResultDto deleteChannelSendEmailCode() throws Exception {

        return sysRemittanceChannelFeignService.deleteChannelSendEmailCode();
    }
}
