/*
 * Decompiled with CFR 0_123.
 */
package com.zakscode.FormulaManager;

import com.zakscode.FormulaManager.ComponentQuantity;
import com.zakscode.FormulaManager.TableArray;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

public class Formula
extends ArrayList<ComponentQuantity>
implements Serializable,
TableArray {
    private static final long serialVersionUID = 6070397926573850223L;
    private String name;
    private String description;
    private boolean approved;
    private boolean rejected;
    private Date date;
    private Date proofDate;

    public Formula(String name, String description) {
        this.name = name;
        this.description = description;
        this.approved = false;
        this.rejected = false;
        this.date = Calendar.getInstance().getTime();
        this.proofDate = null;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
        this.date = Calendar.getInstance().getTime();
    }

    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
        this.date = Calendar.getInstance().getTime();
    }

    public boolean getApproved() {
        return this.approved;
    }

    public void setApproved(boolean approved) {
        this.approved = approved;
        this.proofDate = Calendar.getInstance().getTime();
    }

    public boolean getRejected() {
        return this.rejected;
    }

    public void setRejected(boolean rejected) {
        this.rejected = rejected;
        this.proofDate = Calendar.getInstance().getTime();
    }

    public Date getDate() {
        return this.date;
    }

    public Date getProofDate() {
        return this.proofDate;
    }

    public double yield() {
        double yield = 0.0;
        for (ComponentQuantity cq : this) {
            yield += cq.getQuantity();
        }
        return yield;
    }

    public ArrayList<ComponentQuantity> calculateForYield(double newYield) {
        double yield = this.yield();
        Formula newFormula = this;
        for (ComponentQuantity cq : newFormula) {
            cq.setQuantity(Math.round(cq.getQuantity() / yield * newYield));
        }
        return newFormula;
    }

    public void add(String component, double quantity) {
        this.add(new ComponentQuantity(component, quantity));
    }

    @Override
    public Object[] toArray() {
        String status = "";
        if (this.approved) {
            status = "Approved";
        }
        if (this.rejected) {
            status = "Rejected";
        }
        return new Object[]{this.name, this.description, this.date, status, this.proofDate};
    }
}

