import { GoodConfig, GOODS_DATA } from "../goods/good-config";
import { GoodType } from "../goods/good-type.enum";
import { Planet } from "../planet.model";

export class Factory {
  product: GoodConfig;
  private type: GoodType;

  private planet: Planet;


  constructor(config: FactoryConfig) {
    this.product = GOODS_DATA[config.type];
    this.type = config.type;
    this.planet = config.planet;

    const existing = this.planet.getGood(this.type);
    if (existing) {
      existing.productionRate = this.product.baseProduction;
    } else {
      this.planet.addGood({
        amount: 0,
        demandRate: this.product.baseDemand,
        productionRate: this.product.baseProduction,
        productionStorage: this.product.storageLimit,
        type: this.type
      });
    }
  }


}

export interface FactoryConfig {
  type: GoodType;
  planet: Planet;
}