package com.oguerreiro.resilient.expression;

import java.math.BigDecimal;

import com.oguerreiro.resilient.domain.Organization;
import com.oguerreiro.resilient.domain.Period;
import com.oguerreiro.resilient.domain.PeriodVersion;
import com.oguerreiro.resilient.domain.Variable;
import com.oguerreiro.resilient.repository.EmissionFactorRepository;
import com.oguerreiro.resilient.repository.InputDataRepository;

public class OutputVariableExpressionContext extends ExpressionContext {
  private static final String INPUT_VARIABLE = "variable"; // Output variable
  private static final String INPUT_PERIOD = "period";
  private static final String INPUT_PERIODVERSION = "periodVersion";
  private static final String INPUT_OWNER = "owner"; //Organization

  private EmissionFactorRepository emissionfactorRepository;
  private InputDataRepository inputDataRepository;

  /**
   * Sets the inputs names and types. Basic Context for validation
   */
  private OutputVariableExpressionContext(EmissionFactorRepository emissionfactorRepository,
      InputDataRepository inputDataRepository) {
    this(emissionfactorRepository, inputDataRepository, null, null, null, null);
  }

  private OutputVariableExpressionContext(EmissionFactorRepository emissionfactorRepository,
      InputDataRepository inputDataRepository, Variable variable, Period period, PeriodVersion periodVersion,
      Organization owner) {
    this.addInput(INPUT_VARIABLE, Variable.class, variable);
    this.addInput(INPUT_PERIOD, Period.class, period);
    this.addInput(INPUT_PERIODVERSION, PeriodVersion.class, periodVersion);
    this.addInput(INPUT_OWNER, Organization.class, owner);

    this.emissionfactorRepository = emissionfactorRepository;
    this.inputDataRepository = inputDataRepository;
  }

  public static OutputVariableExpressionContext create(EmissionFactorRepository emissionfactorRepository,
      InputDataRepository inputDataRepository, Variable variable, Period period, PeriodVersion periodVersion,
      Organization owner) {
    return new OutputVariableExpressionContext(emissionfactorRepository, inputDataRepository, variable, period,
        periodVersion, owner);
  }

  public static OutputVariableExpressionContext create(EmissionFactorRepository emissionfactorRepository,
      InputDataRepository inputDataRepository) {
    return new OutputVariableExpressionContext(emissionfactorRepository, inputDataRepository);
  }

  public static BigDecimal in(Object... codes) {
    // codes[0] - (String) VariableCode
    // codes[1] - (String) ClassCode

    if (codes.length == 1) {
      return OutputVariableExpressionContext.in((String) codes[0]);
    } else if (codes.length == 2) {
      return OutputVariableExpressionContext.in((String) codes[0], (String) codes[1]);
    }

    return null;
  }

  private static BigDecimal in(String variableCode) {
    return null;
  }

  private static BigDecimal in(String variableCode, String classCode) {
    return null;
  }

  public static BigDecimal out(String variableCode) {
    return null;
  }

  public static BigDecimal fe(String emissionFactorCode) {
    return null;
  }
}
