/******************************************************************************
 * Copyright (c) 2000-2025 Ericsson Telecom AB
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
 *
 * Contributors:
 *   Balasko, Jeno
 *   Raduly, Csaba
 *
 ******************************************************************************/
/*

TTCN-3 equivalents of the examples in Annex C

*/
module X693amd1 {

type integer salary;
//---------- C.2.2
type record Employee {
  integer id,
  charstring recruited,
  record of salary salaries
}
with {
  variant "name as uncapitalized";
  variant (id) "attribute";
  variant (salaries) "list"
}


//---------- C.3.1  USE-UNION
type union Int_or_boolean_u {
  integer int,
  boolean boolean_
}
with {
  variant "useUnion";
  variant (int) "XSD:integer";
  variant (boolean_) "name as 'boolean'";
  variant (boolean_) "XSD:boolean";
}

//---------- C.3.2  USE-TYPE
type union Int_or_boolean_t {
  integer int,
  boolean boolean_,
  charstring text
}
with {
  variant "useType";
  variant (boolean_) "name as 'boolean'"
  //variant (boolean_) "namespace as 'foo:bar:baz' prefix 'foobar'"
}

//---------- C.3.3  USENUMBER, LIST
type enumerated PrimesUnder30 { int2(2), int3(3), int5(5), int7(7), int11(11),
  int13(13), int17(17), int19(19), int23(23), int29(29) }
with {
  variant "useNumber"
}

// record-of
type record of PrimesUnder30 InputValues with {
  variant "attribute"
}

// record-of with LIST
type record of PrimesUnder30 InputValuesList with {
  variant "attribute"
  variant "list"
}

type float REAL;

// record which relies on its record-of member having LIST
type record PrimeProducts {
  InputValuesList input,
  REAL output
}
with {
  variant (input) "attribute"; // it is not enough that InputValuesList has "attribute"
  variant (output) "attribute"
  variant (output) "XSD:decimal"
}

// record which puts LIST on its record-of member
type record PrimeProductsLocalList {
  InputValues input,
  float output
}
with {
  variant (input) "attribute"; // it is not enough that InputValues has "attribute"
  variant (output) "attribute"
  variant (output) "XSD:decimal"
  variant (input) "list"
}

//---------- C.3.4  DEFAULT-FOR-EMPTY
type enumerated Responses { ringing, engaged, number_not_known }
with { variant "text 'number_not_known' as 'number-not-known'"}

type record CallDetails {
  charstring number, // NumericString 
  Responses response
}
with {
  variant "defaultForEmpty as 'number_not_known'";
  variant (number) "attribute";
  variant (response) "untagged"; // Nokalva requires this (correctly, I think)
  // even though it's not in the example from the ASN.1 standard 
}

// Same as above but defaultForEmpty will be applied later
type record CallDetails0 {
  charstring number, // NumericString 
  Responses response
}
with {
    variant (number) "attribute"
    variant (response) "untagged";
    variant "name as 'CallDetails'"; // same name so we can reuse the test strings
}

type CallDetails0 CallDetails_indirect
with {
    variant "defaultForEmpty as 'ringing'";
    variant "name as 'CallDetails'"; // same name so we can reuse the test strings
    //     variant (number) "attribute" not possible here
}

//------------ D-F-E
/*
type charstring NoFoo
with {
  variant "defaultForEmpty as 'foo'"
}

type record NoBar {
  integer nb
}
with {
  variant "useNil";
  variant "defaultForEmpty as '13'"
}
*/

//---------- C.3.5
// embedValues (in EmbedValues.ttcnpp)
//

/* * * * * * * * * * * * * * * * * * */
// USE-NIL

type record nilluser {
  charstring title,
  integer maybe optional
}
with {
  variant (title) "attribute"
  variant "useNil"
}

/* * * * * * * * * * * * * * * * * * */
// TEXT, from the TTCN standard, 5.2.2
type enumerated State { magic(-13), more_magic(17) }
with {
  variant "name as uncapitalized";
  variant "text all as capitalized";
  variant "text 'more_magic' as 'off'"
}

/* * * * * * * * * * * * * * * * * * */

type boolean textboolean
with { variant "text" }

/* * * * * * * * * * * * * * * * * * */
// Nillable (nested USE-NIL)

type record Nillable {
  record {
    record { charstring content optional } forename 
  } content optional
}
with {
  variant "useNil";
  variant (content.forename) "useNil";
}

}
with {
encode "XML"
//variant "controlNamespace 'c\x94ntr\x94l-n\x82mszp\x82sz'" // required by USE-NIL and USE-TYPE
variant "controlNamespace 'cns' prefix 'p'"
}
