/**
 *  Copyright (c) 2017 CentraleSupélec & EDF.
 *  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
 * 
 *  This file is part of the RiseClipse tool
 *  
 *  Contributors:
 *      Computer Science Department, CentraleSupélec
 *      EDF R&D
 *  Contacts:
 *      dominique.marcadet@centralesupelec.fr
 *      aurelie.dehouck-neveu@edf.fr
 *  Web site:
 *      http://wdi.supelec.fr/software/RiseClipse/
 */
import scl: 'http://www.iec.ch/61850/2003/SCL'

package scl

context VoltageLevel

    -- Within a VoltageLevel, there cannot be two LNode elements with the same
    -- combination of lnInst, lnClass, iedName, ldInst, and prefix.
    -- done in LNodeContainer.ocl

    -- Within a VoltageLevel, there cannot be two direct PowerTransformer elements
    -- with the same name.
    -- done in EquipmentContainer.ocl

    -- Within a VoltageLevel, there cannot be two direct GeneralEquipment elements
    -- with the same name.
    -- done in EquipmentContainer.ocl

    -- Within a VoltageLevel, there cannot be two Bay elements with the
    -- same name.
    inv VoltageLevel_unique_Bay_name
    ( 'Bay in VoltageLevel shall have different name (line ' + self.lineNumber.toString() + ')' )
    :
        self.Bay->isUnique( v : Bay | v.name )

    -- Within a VoltageLevel, there cannot be two Function elements with the same
    -- name.
    inv VoltageLevel_unique_Function_name
    ( 'Function in VoltageLevel shall have different name (line ' + self.lineNumber.toString() + ')' )
    :
        self.Function->isUnique( f : Function | f.name )

    -- In order to avoid any ambiguities, within a VoltageLevel there cannot be two
    -- direct child elements with the same name.
    inv VoltageLevel_unique_DirectChild_name
    ( 'All direct childs in VoltageLevel shall have different name (line ' + self.lineNumber.toString() + ')' )
    :
        self.oclContents()->selectByKind( scl::Naming )->isUnique( n : Naming | n.name )
        -- Version when oclContents() is not available
        --   let childs_1 : OrderedSet( Naming ) = self.Function
        --in let childs_2 : OrderedSet( Naming ) = childs_1->union( self.GeneralEquipment )
        --in let childs_3 : OrderedSet( Naming ) = childs_2->union( self.PowerTransformer )
        --in let childs_4 : OrderedSet( Naming ) = childs_3->union( self.Bay )
        --in childs_4->isUnique( n : Naming | n.name )


endpackage