package com.izouma.nineth.web;

import com.izouma.nineth.dto.BindCardRequest;
import com.izouma.nineth.service.UserBankCardService;
import com.izouma.nineth.utils.SecurityUtils;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/userBankCard")
@Slf4j
@AllArgsConstructor
public class UserBankCardController {
    private final UserBankCardService userBankCardService;

    @PostMapping("/bindCard")
    public Map<String, String> bindCard(@RequestParam String phone, @RequestParam String bankNo) {
        return userBankCardService.bindCard(SecurityUtils.getAuthenticatedUser().getId(), phone, bankNo);
    }

    @PostMapping("/bindCardConfirm")
    public void bindCardConfirm(@RequestParam String bindCardId, @RequestParam String code) {
        userBankCardService.bindCardConfirm(bindCardId, code);
    }

    @PostMapping("/bindCardCaptcha")
    public void bindCardCaptcha(@RequestParam String bindCardId) {
        userBankCardService.bindCardCaptcha(bindCardId);
    }

    @PostMapping("/unbind")
    public void unbind() {
        userBankCardService.unbind(SecurityUtils.getAuthenticatedUser().getId());
    }
}
