package com.crm.ucard.controller;

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.ucard.CardNumberDto;
import com.crm.rely.backend.core.entity.base.BaseDeleteEntities;
import com.crm.rely.backend.core.entity.ucard.CardNumberAddEntity;
import com.crm.rely.backend.core.entity.ucard.CardNumberPageEntity;
import com.crm.rely.backend.core.entity.ucard.CardNumberUpdateEntity;
import com.crm.rely.backend.core.entity.ucard.CardNumberVerifyEntity;
import com.crm.rely.backend.exception.ServiceException;
import com.crm.ucard.service.UcardNumberService;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * 银行卡服务接口
 */
@Slf4j
@RestController
@RequestMapping("/ucard/number/manager")
public class ManagerUcardNumberController {

    @Autowired
    private UcardNumberService ucardNumberService;

    /**
     * 校验实体卡卡号是否使用过
     */
    @PostMapping("/verify")
    @FeignClientAnnotation
    public BaseResultDto cardNumberVerify(@RequestBody @Validated CardNumberVerifyEntity entity) throws ServiceException {
        return ucardNumberService.cardNumberVerify(entity);
    }

    /**
     * 导入卡号
     */
    @PostMapping("/import")
    @FeignClientAnnotation
    BaseResultDto cardNumberImport(@RequestBody List<CardNumberAddEntity> entityList) throws ServiceException {
        return ucardNumberService.cardNumberImport(entityList);
    }

    /**
     * 卡号列表
     */
    @PostMapping("/list")
    @FeignClientAnnotation
    ResultWithPagerDto<CardNumberDto> queryCardNumberList(@RequestBody CardNumberPageEntity entity) throws ServiceException {
        return ucardNumberService.queryCardNumberList(entity);
    }

    /**
     * 卡号列表
     */
    @PostMapping("/dropdown")
    @FeignClientAnnotation
    BaseResultDto queryCardNumberDropdown(@RequestBody CardNumberPageEntity entity) throws ServiceException {
        return ucardNumberService.queryCardNumberDropdown(entity);
    }

    /**
     * 修改卡号状态
     */
    @PostMapping("/update/status")
    @FeignClientAnnotation
    BaseResultDto saveCardNumberStatus(@RequestBody CardNumberUpdateEntity entity) throws ServiceException {
        return ucardNumberService.saveCardNumberStatus(entity);
    }

    /**
     * 删除实体卡卡号
     */
    @PostMapping("/delete")
    @FeignClientAnnotation
    public BaseResultDto deleteCardNumber(@RequestBody BaseDeleteEntities entity) throws ServiceException {
        return ucardNumberService.deleteCardNumber(entity);
    }

}
