package com.lovecoding.day09.ex1;

public class DepositCard extends CreditCard {

    private  int aOverDraft; //可
    private  int bOverDraft; //已经

    @Override
    public void withdraw(int money) {
        if (money <0 ){
            System.out.println("取款金额不能为负数");
        }
        //增加
        /*
        - 取款金额超过账户余额+本月还可透支额度，提示超过可透支额度
        - 取款金额在账户余额范围内，不用透支
        - 取款金额超过账户余额但在可透支范围内，需要透支
         */
        if ( money >  (aOverDraft + this.getMoney() - bOverDraft)){
            System.out.println("超过透支额度");
        }else{
            if (this.getMoney() > money){
                //账户额度
                this.setMoney(this.getMoney() - money);
            }else{
                //减账户
                int i = money - this.getMoney();
                this.setMoney(0);
                //减去透支额度
            }
        }
    }

    @Override
    public void save(int money) {
        //提示负数
        if (money <0 ) {
            System.out.println("存款金额不能为负数");
        }
        //- 本次存款金额只够偿还部分可透支金额
        //- 本次存款金额除了偿还透支金额，还有剩余
        if( money < bOverDraft ){
            bOverDraft = this.bOverDraft - money;
        }else{
            //余额 - 已透支
            this.setMoney(money - bOverDraft + getMoney());
            //减已透支
            bOverDraft = 0 ;
        }

    }

    @Override
    public String getInfo() {
        return super.getInfo()+",aOverDraft:"+aOverDraft+",bOverDraft:"+bOverDraft;
    }

    public int getaOverDraft() {
        return aOverDraft;
    }

    public void setaOverDraft(int aOverDraft) {
        this.aOverDraft = aOverDraft;
    }

    public int getbOverDraft() {
        return bOverDraft;
    }

    public void setbOverDraft(int bOverDraft) {
        this.bOverDraft = bOverDraft;
    }
}
