package ru.upos;

/**
 * Операции, выполняемые на терминале UPOS 1.0
 */
public enum UposOperation {

    Purchase("1", 2),
    Cash("2", 2),
    Refund("3", 2), // TODO: check it
    Settlement("7", 1),
    Reversal("13", 1),
    PurchaseWithCashback("61", 3);

    private final String operationId;
    private final int parametersNum;

    UposOperation(String operationId, int parametersNum) {
        this.operationId = operationId;
        this.parametersNum = parametersNum;
    }

    public String getOperationId() {
        return operationId;
    }
    public int getParametersNum() {
        return parametersNum;
    }

    public static UposOperation getUposOperation(String operation) throws Exception {
        for (UposOperation uposOperation : UposOperation.values()) {
            if (uposOperation.name().equals(operation)
                    || uposOperation.operationId.equals(operation)) {
                return uposOperation;
            }
        }
        throw new Exception("Unknown operation");
    }
}
