package com.ichangzuo.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ichangzuo.common.result.Result;
import com.ichangzuo.system.model.entity.Bank;
import com.ichangzuo.system.model.entity.UserBank;
import com.ichangzuo.system.service.impl.BankServiceImpl;
import com.ichangzuo.system.service.impl.UserBankServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api/v1/bank")
@RequiredArgsConstructor
public class BankController {
    private final BankServiceImpl bankService;
    private final UserBankServiceImpl userBankService;

    @GetMapping("/hotList")
    public Result<List<String>> listHot(){
        List<Bank> bankList = bankService.list(new LambdaQueryWrapper<Bank>()
                .eq(Bank::getIsHot, 1)
                .eq(Bank::getState, 1)
                .orderByDesc(Bank::getBankId));

        List<String> retList = new ArrayList<>();
        bankList.forEach((item)->{
            retList.add(item.getName());
        });

        return Result.success(retList);
    }

    @GetMapping("/me")
    public Result<UserBank> getBankInfo(){
        UserBank bank =  userBankService.getCurrentBankInfo();
        return Result.success(bank);
    }
}
