package com.capgemini.framework.teamcenter.object.pom.workspace.bom;

import com.capgemini.framework.teamcenter.object.pom.workspace.bom.product.TcProduct;
import com.teamcenter.services.strong.cad._2007_01.StructureManagement.RevisionRuleConfigInfo;
import com.teamcenter.services.strong.cad._2007_01.StructureManagement.RevisionRuleEntryProps;

import java.util.Calendar;

public class TcRevisionRuleProperties {
    private final TcProduct product;
    private final int unit;
    private final Calendar effectivityDate;

    public TcRevisionRuleProperties(final TcProduct product, final int unit) {
        this(product, unit, null);
    }

    public TcRevisionRuleProperties(final Calendar effectivityDate) {
        this(null, 0, effectivityDate);
    }

    public TcRevisionRuleProperties(final TcProduct product, final int unit, final Calendar effectivityDate) {
        this.product = product;
        this.unit = unit;
        this.effectivityDate = effectivityDate;
    }

    public void addInfo(final RevisionRuleConfigInfo revisionRuleConfigInfo) {
        RevisionRuleEntryProps props = new RevisionRuleEntryProps();
        // Date used by configuration, else the current date is used for configuration
        if (effectivityDate != null) {
            props.date = effectivityDate;
        } else {
            props.today = true;
        }

        if (product != null) {
            product.addInfo(props);
        }
        props.unitNo = unit;
        revisionRuleConfigInfo.props = props;
    }
}
