/*
 * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.parser.openconfig.stmt;

import org.opendaylight.yangtools.concepts.SemVer;
import org.opendaylight.yangtools.openconfig.model.api.OpenConfigStatements;
import org.opendaylight.yangtools.openconfig.model.api.OpenConfigVersionStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
import org.opendaylight.yangtools.yang.parser.spi.meta.SemanticVersionNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext.Mutable;
import org.opendaylight.yangtools.yang.parser.spi.meta.SubstatementValidator;

public final class OpenConfigVersionSupport extends AbstractStatementSupport<SemVer, OpenConfigVersionStatement,
        EffectiveStatement<SemVer, OpenConfigVersionStatement>> {
    private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
        OpenConfigStatements.OPENCONFIG_VERSION).build();
    private static final OpenConfigVersionSupport INSTANCE = new OpenConfigVersionSupport();

    private OpenConfigVersionSupport() {
        super(OpenConfigStatements.OPENCONFIG_VERSION);
    }

    public static OpenConfigVersionSupport getInstance() {
        return INSTANCE;
    }

    @Override
    public SemVer parseArgumentValue(final StmtContext<?, ?, ?> ctx, final String value) {
        return SemVer.valueOf(value);
    }

    @Override
    public void onLinkageDeclared(final Mutable<SemVer, OpenConfigVersionStatement,
            EffectiveStatement<SemVer, OpenConfigVersionStatement>> stmt) {
        stmt.addToNs(SemanticVersionNamespace.class, stmt.getParentContext(), stmt.getStatementArgument());
    }

    @Override
    public OpenConfigVersionStatement createDeclared(final StmtContext<SemVer, OpenConfigVersionStatement, ?> ctx) {
        return new OpenConfigVersionStatementImpl(ctx);
    }

    @Override
    public EffectiveStatement<SemVer, OpenConfigVersionStatement> createEffective(
            final StmtContext<SemVer, OpenConfigVersionStatement,
            EffectiveStatement<SemVer, OpenConfigVersionStatement>> ctx) {
        return new OpenConfigVersionEffectiveStatementImpl(ctx);
    }

    @Override
    protected SubstatementValidator getSubstatementValidator() {
        return SUBSTATEMENT_VALIDATOR;
    }
}
@@ -568,32 +568,41 @@
 penConfigVersion
+Effective
 Statement;%0Aimpor
@@ -630,19 +630,25 @@
 ngtools.
-yan
+openconfi
 g.model.
@@ -655,22 +655,25 @@
 api.
-meta.Effective
+OpenConfigVersion
 Stat
@@ -1107,16 +1107,24 @@
 nSupport
+%0A       
  extends
@@ -1188,43 +1188,8 @@
 ent,
-%0A        EffectiveStatement%3CSemVer,
  Ope
@@ -1194,32 +1194,41 @@
 penConfigVersion
+Effective
 Statement%3E%3E %7B%0A  
@@ -1221,17 +1221,16 @@
 atement%3E
-%3E
  %7B%0A    p
@@ -1868,24 +1868,37 @@
 ageDeclared(
+%0A            
 final Mutabl
@@ -1938,47 +1938,8 @@
 ent,
-%0A            EffectiveStatement%3CSemVer,
  Ope
@@ -1944,32 +1944,41 @@
 penConfigVersion
+Effective
 Statement%3E%3E stmt
@@ -1971,17 +1971,16 @@
 atement%3E
-%3E
  stmt) %7B
@@ -2317,35 +2317,8 @@
 blic
- EffectiveStatement%3CSemVer,
  Ope
@@ -2323,32 +2323,41 @@
 penConfigVersion
+Effective
 Statement%3E creat
@@ -2349,17 +2349,16 @@
 tatement
-%3E
  createE
@@ -2436,47 +2436,8 @@
 ent,
-%0A            EffectiveStatement%3CSemVer,
  Ope
@@ -2442,32 +2442,41 @@
 penConfigVersion
+Effective
 Statement%3E%3E ctx)
@@ -2469,17 +2469,16 @@
 atement%3E
-%3E
  ctx) %7B%0A

Clean up OpenConfigVersionSupport