/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.daffodil.grammar.primitives

import org.apache.daffodil.grammar.Terminal
import org.apache.daffodil.dsom.ElementBase
import org.apache.daffodil.processors.parsers.BinaryIntegerRuntimeLengthParser
import org.apache.daffodil.processors.parsers.BinaryIntegerKnownLengthParser
import org.apache.daffodil.processors.parsers.BinaryDecimalRuntimeLengthParser
import org.apache.daffodil.processors.parsers.BinaryDecimalKnownLengthParser
import org.apache.daffodil.processors.parsers.BinaryFloatParser
import org.apache.daffodil.processors.parsers.BinaryDoubleParser
import org.apache.daffodil.processors.unparsers.Unparser
import org.apache.daffodil.processors.unparsers.BinaryIntegerKnownLengthUnparser
import org.apache.daffodil.processors.unparsers.BinaryIntegerRuntimeLengthUnparser
import org.apache.daffodil.processors.unparsers.BinaryDecimalRuntimeLengthUnparser
import org.apache.daffodil.processors.unparsers.BinaryDecimalKnownLengthUnparser
import org.apache.daffodil.processors.unparsers.BinaryDoubleUnparser
import org.apache.daffodil.processors.unparsers.BinaryFloatUnparser

class BinaryIntegerRuntimeLength(val e: ElementBase, signed: Boolean) extends Terminal(e, true) {

  override lazy val parser = new BinaryIntegerRuntimeLengthParser(e.elementRuntimeData, signed, e.lengthEv, e.lengthUnits)

  override lazy val unparser: Unparser = new BinaryIntegerRuntimeLengthUnparser(e.elementRuntimeData, signed, e.lengthEv, e.lengthUnits)
}

class BinaryIntegerKnownLength(val e: ElementBase, signed: Boolean, lengthInBits: Long) extends Terminal(e, true) {

  override lazy val parser = {
    new BinaryIntegerKnownLengthParser(e.elementRuntimeData, signed, lengthInBits.toInt)
  }

  override lazy val unparser: Unparser = new BinaryIntegerKnownLengthUnparser(e.elementRuntimeData, signed, lengthInBits.toInt)
}

class BinaryDecimalRuntimeLength(val e: ElementBase) extends Terminal(e, true) {

  override lazy val parser = new BinaryDecimalRuntimeLengthParser(e.elementRuntimeData, e.decimalSigned, e.binaryDecimalVirtualPoint, e.lengthEv, e.lengthUnits)

  override lazy val unparser: Unparser = new BinaryDecimalRuntimeLengthUnparser(e.elementRuntimeData, e.decimalSigned, e.binaryDecimalVirtualPoint, e.lengthEv, e.lengthUnits)

}

class BinaryDecimalKnownLength(val e: ElementBase, lengthInBits: Long) extends Terminal(e, true) {

  override lazy val parser = new BinaryDecimalKnownLengthParser(e.elementRuntimeData, e.decimalSigned, e.binaryDecimalVirtualPoint, lengthInBits.toInt)

  override lazy val unparser: Unparser = new BinaryDecimalKnownLengthUnparser(e.elementRuntimeData, e.decimalSigned, e.binaryDecimalVirtualPoint, lengthInBits.toInt)
}

class BinaryFloat(val e: ElementBase) extends Terminal(e, true) {

  override lazy val parser = new BinaryFloatParser(e.elementRuntimeData)

  override lazy val unparser: Unparser = new BinaryFloatUnparser(e.elementRuntimeData)
}

class BinaryDouble(val e: ElementBase) extends Terminal(e, true) {

  override lazy val parser = new BinaryDoubleParser(e.elementRuntimeData)

  override lazy val unparser: Unparser = new BinaryDoubleUnparser(e.elementRuntimeData)
}
