// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/project/FeatureTask.java
// public class FeatureTask implements ProjectTask {
// 
//     private ProductFeature mFeature;
//     private int mStartLevel;
//     private int mEndLevel;
// 
//     public FeatureTask(ProductFeature feature, int fromLevel, int toLevel) {
//         mFeature = feature;
//         mStartLevel = fromLevel;
//         mEndLevel = toLevel;
//     }
// 
//     @Override
//     public String getTaskTitle() {
//         return mFeature.getName() + " to level " + mEndLevel;
//     }
// 
//     @Override
//     public long getQuantity() {
//         return mEndLevel - mStartLevel;
//     }
// 
//     @Override
//     public String getTextualQuantity() {
//         return "+" + getQuantity();
//     }
// 
//     @Override
//     public long getWorkAmount() {
//         return mFeature.getComplexityForUpgrade(mStartLevel, mEndLevel);
//     }
// }
// 
// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/project/NewProductTask.java
// public class NewProductTask implements ProjectTask {
// 
//     /** The new product being developed. */
//     private Product mProduct;
// 
//     public NewProductTask(Product product) {
//         mProduct = product;
//     }
// 
//     @Override
//     public String getTaskTitle() {
//         return "Product Development";
//     }
// 
//     @Override
//     public long getQuantity() {
//         return 1;
//     }
// 
//     @Override
//     public String getTextualQuantity() {
//         return null;
//     }
// 
//     @Override
//     public long getWorkAmount() {
//         // Work amount for the "initial development" of the product.
//         //
//         // [base complexity of the product type] * 2 ^ [number of features] = [work amount]
//         long workAmount = mProduct.getType().getBaseComplexity();
//         workAmount = (long) (workAmount * Math.pow(2, mProduct.getFeatures().size()));
// 
//         return workAmount;
//     }
// }
// 
// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/project/ProductDevelopmentProject.java
// public class ProductDevelopmentProject extends Project {
// 
//     private Product mProduct;
//     private double mFractionalQuality;
//     private long mQualityGain;
// 
//     public ProductDevelopmentProject(String description, Product product) {
//         // Name of the new product dev. project is "New [product type]"
//         super("R&D - " + product.getType().getName(), description);
//         mProduct = product;
//     }
// 
//     @Override
//     protected long calculateWorkAmount() {
// 
//         long workAmount = 0;
// 
//         // Work amount is the sum of work amounts of all the tasks.
//         for (ProjectTask task : mTasks) {
//             workAmount += task.getWorkAmount();
//         }
// 
//         return workAmount;
//     }
// 
//     @Override
//     public boolean isReady() {
//         return true;
//     }
// 
//     /** Delivering the project releases the new version of the product. */
//     @Override
//     public void deliver() {
//         mProduct.releaseNextVersion();
//         GameEngine.getInstance().getGameState().getCompany().onIncomeChanged();
// 
//         Toast.makeText(AppTycoonApp.getContext(),
//                 mProduct.getName() + " released",
//                 Toast.LENGTH_LONG).show();
//     }
// 
//     public void removeAllTasks() {
//         mTasks = new ArrayList<>();
//     }
// 
//     @Override
//     public void progress(double workAmount, double qualityAmount, long time) {
//         super.progress(workAmount, qualityAmount, time);
// 
//         // Add quality gain.
//         mFractionalQuality += qualityAmount;
//         long qualityIntPart = (long) mFractionalQuality;
//         mFractionalQuality -= qualityIntPart;
//         mQualityGain += qualityIntPart;
// 
//     }
// 
//     public long getQualityGain() {
//         return mQualityGain;
//     }
// }


import android.support.v4.util.Pair;
import android.util.Log;
import android.util.SparseArray;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import jaakko.jaaska.apptycoon.engine.project.FeatureTask;
import jaakko.jaaska.apptycoon.engine.project.NewProductTask;
import jaakko.jaaska.apptycoon.engine.project.ProductDevelopmentProject;
package jaakko.jaaska.apptycoon.engine.product;




/**
 * TODO: Refactor the ProductFeatures to be similar to EmployeeType: instance specific data (like level) into ProductFeature class, Product to have its features as List<ProductFeature>.
 */

public class Product {

    private static final String TAG = "Product";

    private String mName;

    /** Number of releases of this product */
    private int mReleaseCount;

    /** The main type */
    private ProductType mType;

    /** Features and their current levels */
    private List<Pair<ProductFeature, Integer>> mFeatures;

    /** Sub-products */
    private List<Product> mSubProducts;

    /** The version of this product currently in distribution */
    private Product mReleasedVersion;

    /** Calculated complexity of the product */
    private long mComplexity;

    /** Current quality of the product */
    private long mQuality;

    /** Number of active users the product has */
    private long mUsers;

    /** Number of all-time downloads (or purchases for a paid product) */
    private long mDownloads;

    /** Money made from one sold unit */
    private int mUnitPrice;

    /** Amount of money the product has earned all-time */
    private long mTotalEarnings;

    /**
     * Array of all the features that directly generate income.
     * Key of the array is the ID of the feature.
     *
     * All income values are money per second per active user.
     */
    private SparseArray<Double> mFeatureIncomes;

    /** The development project for the next release. This will be null until the next version
     * is defined. Be sure to nullify this after the project is done!
     */
// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/project/FeatureTask.java
// public class FeatureTask implements ProjectTask {
// 
//     private ProductFeature mFeature;
//     private int mStartLevel;
//     private int mEndLevel;
// 
//     public FeatureTask(ProductFeature feature, int fromLevel, int toLevel) {
//         mFeature = feature;
//         mStartLevel = fromLevel;
//         mEndLevel = toLevel;
//     }
// 
//     @Override
//     public String getTaskTitle() {
//         return mFeature.getName() + " to level " + mEndLevel;
//     }
// 
//     @Override
//     public long getQuantity() {
//         return mEndLevel - mStartLevel;
//     }
// 
//     @Override
//     public String getTextualQuantity() {
//         return "+" + getQuantity();
//     }
// 
//     @Override
//     public long getWorkAmount() {
//         return mFeature.getComplexityForUpgrade(mStartLevel, mEndLevel);
//     }
// }
// 
// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/project/NewProductTask.java
// public class NewProductTask implements ProjectTask {
// 
//     /** The new product being developed. */
//     private Product mProduct;
// 
//     public NewProductTask(Product product) {
//         mProduct = product;
//     }
// 
//     @Override
//     public String getTaskTitle() {
//         return "Product Development";
//     }
// 
//     @Override
//     public long getQuantity() {
//         return 1;
//     }
// 
//     @Override
//     public String getTextualQuantity() {
//         return null;
//     }
// 
//     @Override
//     public long getWorkAmount() {
//         // Work amount for the "initial development" of the product.
//         //
//         // [base complexity of the product type] * 2 ^ [number of features] = [work amount]
//         long workAmount = mProduct.getType().getBaseComplexity();
//         workAmount = (long) (workAmount * Math.pow(2, mProduct.getFeatures().size()));
// 
//         return workAmount;
//     }
// }
// 
// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/project/ProductDevelopmentProject.java
// public class ProductDevelopmentProject extends Project {
// 
//     private Product mProduct;
//     private double mFractionalQuality;
//     private long mQualityGain;
// 
//     public ProductDevelopmentProject(String description, Product product) {
//         // Name of the new product dev. project is "New [product type]"
//         super("R&D - " + product.getType().getName(), description);
//         mProduct = product;
//     }
// 
//     @Override
//     protected long calculateWorkAmount() {
// 
//         long workAmount = 0;
// 
//         // Work amount is the sum of work amounts of all the tasks.
//         for (ProjectTask task : mTasks) {
//             workAmount += task.getWorkAmount();
//         }
// 
//         return workAmount;
//     }
// 
//     @Override
//     public boolean isReady() {
//         return true;
//     }
// 
//     /** Delivering the project releases the new version of the product. */
//     @Override
//     public void deliver() {
//         mProduct.releaseNextVersion();
//         GameEngine.getInstance().getGameState().getCompany().onIncomeChanged();
// 
//         Toast.makeText(AppTycoonApp.getContext(),
//                 mProduct.getName() + " released",
//                 Toast.LENGTH_LONG).show();
//     }
// 
//     public void removeAllTasks() {
//         mTasks = new ArrayList<>();
//     }
// 
//     @Override
//     public void progress(double workAmount, double qualityAmount, long time) {
//         super.progress(workAmount, qualityAmount, time);
// 
//         // Add quality gain.
//         mFractionalQuality += qualityAmount;
//         long qualityIntPart = (long) mFractionalQuality;
//         mFractionalQuality -= qualityIntPart;
//         mQualityGain += qualityIntPart;
// 
//     }
// 
//     public long getQualityGain() {
//         return mQualityGain;
//     }
// }


// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/product/Product.java
import android.support.v4.util.Pair;
import android.util.Log;
import android.util.SparseArray;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import jaakko.jaaska.apptycoon.engine.project.FeatureTask;
import jaakko.jaaska.apptycoon.engine.project.NewProductTask;
import jaakko.jaaska.apptycoon.engine.project.ProductDevelopmentProject;

package jaakko.jaaska.apptycoon.engine.product;




/**
 * TODO: Refactor the ProductFeatures to be similar to EmployeeType: instance specific data (like level) into ProductFeature class, Product to have its features as List<ProductFeature>.
 */

public class Product {

    private static final String TAG = "Product";

    private String mName;

    /** Number of releases of this product */
    private int mReleaseCount;

    /** The main type */
    private ProductType mType;

    /** Features and their current levels */
    private List<Pair<ProductFeature, Integer>> mFeatures;

    /** Sub-products */
    private List<Product> mSubProducts;

    /** The version of this product currently in distribution */
    private Product mReleasedVersion;

    /** Calculated complexity of the product */
    private long mComplexity;

    /** Current quality of the product */
    private long mQuality;

    /** Number of active users the product has */
    private long mUsers;

    /** Number of all-time downloads (or purchases for a paid product) */
    private long mDownloads;

    /** Money made from one sold unit */
    private int mUnitPrice;

    /** Amount of money the product has earned all-time */
    private long mTotalEarnings;

    /**
     * Array of all the features that directly generate income.
     * Key of the array is the ID of the feature.
     *
     * All income values are money per second per active user.
     */
    private SparseArray<Double> mFeatureIncomes;

    /** The development project for the next release. This will be null until the next version
     * is defined. Be sure to nullify this after the project is done!
     */
    private ProductDevelopmentProject mDevProject;