package com.sf._02_list.demo2;

public class Goods {
    private Long id;
    private String name;
    private double price;
    private int stock;


    /**
     * 判断库存是否足够
     */
    public boolean isStockEnough(int buyNum){
        if(buyNum<= stock){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 扣减库存
     */
    public void reduceStock(int buyNum){
        // 1 判断库存是否
        boolean stockEnough = isStockEnough(buyNum);
        // 2 如果足够再去扣减库存
        if(stockEnough){
            this.stock -= buyNum;
            System.out.println("扣减成功,扣减完以后还剩:"+ stock);
        }else{
            System.out.println("库存不足");
        }
    }

    public Goods() {
    }

    public Goods(Long id, String name, double price, int stock) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
    }

    /**
     * 获取
     * @return id
     */
    public Long getId() {
        return id;
    }

    /**
     * 设置
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return price
     */
    public double getPrice() {
        return price;
    }

    /**
     * 设置
     * @param price
     */
    public void setPrice(double price) {
        this.price = price;
    }

    /**
     * 获取
     * @return stock
     */
    public int getStock() {
        return stock;
    }

    /**
     * 设置
     * @param stock
     */
    public void setStock(int stock) {
        this.stock = stock;
    }

    public String toString() {
        return "Goods{id = " + id + ", name = " + name + ", price = " + price + ", stock = " + stock + "}";
    }
}
