//*****************************************************************
// IDAutomation.NetStandard C# 2017
// © Copyright 2017, IDAutomation.com, Inc. All rights reserved.
// USA Patent 7,637,436 B1
// 
// DEMO VERSION NOTICE:
// The demo version of this product contains a static barcode that may be
// used for evaluation purposes only. It may be copied into another report 
// and distributed to prove its functionality. The static barcode cannot be
// changed because this would reveal the complete formula, which is only
// available in the licensed version. The licensed version is provided 
// with a 30 day money back satisfaction guarantee. If it is necessary to 
// test dynamic barcodes with this product, the licensed version is required.
// 
// Purchase Link:
// www.idautomation.com/barcode-components/dotnet-standard/
// 
// User Manual:
// www.idautomation.com/barcode-components/dotnet-standard/user-manual.html
// 
//*****************************************************************
using System;
using System.Text;

namespace IDAutomation.NetStandard
{
    public class QRCode
    {
        string Debug = "";
      
        private StringBuilder _DataToEncode = new StringBuilder("123456789012");
        private bool _ApplyTilde = false;
        private int _EncodingMode = 0;
        private int _ErrorLevel = 0;
        private bool _BestMask = false;
        private int _QuietZone = 1;
        private int _Version = 0;
        private int iFNC1 = 0;
        private int iFNC1_AI = 0;
        private int[][] Matrix;
        private int Size = 0;


        /// <summary>
        /// Function, which creates a QR-Code barcode, depending on the various input options chosen.
        /// </summary>
        /// <param name="DataToEncode">The data that is encoded in the barcode.</param>
        /// <param name="ApplyTilde">Enables processing of tilde and parentheses characters for purposes of encoding ASCII functions and GS1 application identifiers.</param>
        /// <param name="EncodingMode"> Various modes used to Data represented in the symbol may be encoded by one of these types.</param>
        /// <param name="Version">Represent the various sizes of the symbol.</param>
        /// <param name="ErrorCorrectionLevel">Four levels of Reed-Solomon error correction, which allow verification of data and recovery in the event that part of the symbol is physically damaged.</param>
        /// <param name="OutputType">Various types of output.</param>
        /// <param name="BestMask">Use a best mask for pattern in the QRCode.</param>
        /// <returns>Encoded text for use with IDAutomation2D font, a native object which use proportional (standard) fonts, or a native object which use proportional (standard) fonts</returns>
        public string EncodeQR(string DataToEncode, bool ApplyTilde = true, EncodingModes EncodingMode = EncodingModes.Byte, Versions Version = Versions.AUTO, ErrorCorrectionLevels ErrorCorrectionLevel = ErrorCorrectionLevels.M, OutputTypes OutputType = OutputTypes.IDA2DFont, bool BestMask = true)
        {

            switch (OutputType)
            {
                case OutputTypes.IDAMonospaceFont:
                    return "█▀▀▀▀▀█ ▄▄▄█▄ █▀▀▀▀▀█\r\n█ ███ █  ▄▀   █ ███ █\r\n█ ▀▀▀ █ ▀▀ █▀ █ ▀▀▀ █\r\n▀▀▀▀▀▀▀ ▀▄▀ ▀ ▀▀▀▀▀▀▀\r\n█ █▄▀▄▀  ▄ ▄▀▄▄▄▀▄ ▀▄\r\n▄▀▀▄▄▄▀▀▄▀▀█▄▀█ ▄▀▄▀█\r\n ▀ ▀▀▀▀ ▄█▄█ ▀▄▄▄▄▀ █\r\n█▀▀▀▀▀█    ▄▀██ ▀▀▀▄▀\r\n█ ███ █ ▀█▀▄▀█▄█▀ █▄ \r\n█ ▀▀▀ █ ▀█  █▄ ▀█ ▀▄█\r\n▀▀▀▀▀▀▀ ▀  ▀▀  ▀ ▀▀ ▀\r\n";

                case OutputTypes.IDAProportionalFont:
                    return "█▀▀▀▀▀█░▄▄▄█▄░█▀▀▀▀▀█\r\n█░███░█░░▄▀░░░█░███░█\r\n█░▀▀▀░█░▀▀░█▀░█░▀▀▀░█\r\n▀▀▀▀▀▀▀░▀▄▀░▀░▀▀▀▀▀▀▀\r\n█░█▄▀▄▀░░▄░▄▀▄▄▄▀▄░▀▄\r\n▄▀▀▄▄▄▀▀▄▀▀█▄▀█░▄▀▄▀█\r\n░▀░▀▀▀▀░▄█▄█░▀▄▄▄▄▀░█\r\n█▀▀▀▀▀█░░░░▄▀██░▀▀▀▄▀\r\n█░███░█░▀█▀▄▀█▄█▀░█▄░\r\n█░▀▀▀░█░▀█░░█▄░▀█░▀▄█\r\n▀▀▀▀▀▀▀░▀░░▀▀░░▀░▀▀░▀\r\n";

                default:
                    return "AHEEEHAPLKJDLPAHEEEHA\r\nBNFFFNBPFGNDFPBNFFFNB\r\nCNBKGKFNOJNIGJILGJOFI\r\nMFNFFFEPLDLCNEILJJFOB\r\nAPBBBPAPFAHLECLBEPBKM\r\nHHHHHHHPHPPHHPPHPHHPH\r\n";
            }
        }
    }
}

//ENUMERATIONS:
    namespace IDAutomation.NetStandard
{
    /// <summary>
    /// Various modes used to Data represented in the symbol may be encoded by one of these types.
    /// </summary>
    public enum EncodingModes
    {
        /// <summary>
        /// In this mode data is encoded at 8 bits per character.
        /// </summary>
        Byte,

        /// <summary>
        /// Encodes data from a set of 45 characters 10 numeric digits 0-9, 26 capital alpha characters A-Z,
        /// and 9 symbols ( space, $, %, *, +, -, ., :, / ) 
        /// Normally, two input characters are represented by 11 bits.
        /// </summary>
        Alphanumeric,
#if !(PCL) //temporarily disabled until can fix bug in EncodeBytes function

        /// <summary>
        /// Encodes data from the decimal set 0-9,
        /// Normally, 3 data characters are represented by 10 bits.
        /// </summary>
        Numeric
#endif
    }
    /// <summary>
    /// Four levels of Reed-Solomon error correction, which allow verification of data and recovery in the event that part of the symbol is physically damaged. 
    /// </summary>
    
    public enum ErrorCorrectionLevels
    {
        /// <summary>
        /// Level M, 15% recovery capacity.
        /// </summary>
        M,

        /// <summary>
        /// Level H, 30% recovery capacity.
        /// </summary>
        H,

        /// <summary>
        /// Level L, 7% recovery capacity.
        /// </summary>
        L,

        /// <summary>
        /// Level Q, 25% recovery capacity.
        /// </summary>
        Q
    }

    /// <summary>
    /// Represent the various sizes of the symbol.
    /// </summary>
    public enum Versions
    {
        /// <summary>
        /// 11 x 11 Format (Micro QR-Code).
        /// </summary>
        M1 = -4,

        /// <summary>
        /// 13 x 13 Format (Micro QR-Code).
        /// </summary>
        M2 = -3,

        /// <summary>
        /// 15 x 15 Format (Micro QR-Code).
        /// </summary>
        M3 = -2,

        /// <summary>
        /// 17 x 17 Format (Micro QR-Code).
        /// </summary>
        M4 = -1,

        /// <summary>
        /// Auto (QR-Code).
        /// </summary>
        AUTO = 0,

        /// <summary>
        /// 21 x 21 Format (QR-Code).
        /// </summary>
        V01,
        /// <summary>
        /// 25 x 25 Format (QR-Code).
        /// </summary>
        V02,
        /// <summary>
        /// 29 x 29 Format (QR-Code).
        /// </summary>
        V03,
        /// <summary>
        /// 33 x 33 Format (QR-Code).
        /// </summary>
        V04,
        /// <summary>
        /// 37 x 37 Format (QR-Code).
        /// </summary>
        V05,
        /// <summary>
        /// 41 x 41 Format (QR-Code).
        /// </summary>
        V06,
        /// <summary>
        /// 45 x 45 Format (QR-Code).
        /// </summary>
        V07,
        /// <summary>
        /// 49 x 49 Format (QR-Code).
        /// </summary>
        V08,
        /// <summary>
        /// 53 x 53 Format (QR-Code).
        /// </summary>
        V09,
        /// <summary>
        /// 57 x 57 Format (QR-Code).
        /// </summary>
        V10,
        /// <summary>
        /// 61 x 61 Format (QR-Code).
        /// </summary>
        V11,
        /// <summary>
        /// 65 x 65 Format (QR-Code).
        /// </summary>
        V12,
        /// <summary>
        /// 69 x 69 Format (QR-Code).
        /// </summary>
        V13,
        /// <summary>
        /// 73 x 73 Format (QR-Code).
        /// </summary>
        V14,
        /// <summary>
        /// 77 x 77 Format (QR-Code).
        /// </summary>
        V15,
        /// <summary>
        /// 81 x 81 Format (QR-Code).
        /// </summary>
        V16,
        /// <summary>
        /// 85 x 85 Format (QR-Code).
        /// </summary>
        V17,
        /// <summary>
        /// 89 x 89 Format (QR-Code).
        /// </summary>
        V18,
        /// <summary>
        /// 93 x 93 Format (QR-Code).
        /// </summary>
        V19,
        /// <summary>
        /// 97 x 97 Format (QR-Code).
        /// </summary>
        V20,
        /// <summary>
        /// 101 x 101 Format (QR-Code).
        /// </summary>
        V21,
        /// <summary>
        /// 105 x 105 Format (QR-Code).
        /// </summary>
        V22,
        /// <summary>
        /// 109 x 109 Format (QR-Code).
        /// </summary>
        V23,
        /// <summary>
        /// 113 x 113 Format (QR-Code).
        /// </summary>
        V24,
        /// <summary>
        /// 117 x 117 Format (QR-Code).
        /// </summary>
        V25,
        /// <summary>
        /// 121 x 121 Format (QR-Code).
        /// </summary>
        V26,
        /// <summary>
        /// 125 x 125 Format (QR-Code).
        /// </summary>
        V27,
        /// <summary>
        /// 129 x 129 Format (QR-Code).
        /// </summary>
        V28,
        /// <summary>
        /// 133 x 133 Format (QR-Code).
        /// </summary>
        V29,
        /// <summary>
        /// 137 x 137 Format (QR-Code).
        /// </summary>
        V30,
        /// <summary>
        /// 141 x 141 Format (QR-Code).
        /// </summary>
        V31,
        /// <summary>
        /// 145 x 145 Format (QR-Code).
        /// </summary>
        V32,
        /// <summary>
        /// 149 x 149 Format (QR-Code).
        /// </summary>
        V33,
        /// <summary>
        /// 153 x 153 Format (QR-Code).
        /// </summary>
        V34,
        /// <summary>
        /// 157 x 157 Format (QR-Code).
        /// </summary>
        V35,
        /// <summary>
        /// 161 x 161 Format (QR-Code).
        /// </summary>
        V36,
        /// <summary>
        /// 165 x 165 Format (QR-Code).
        /// </summary>
        V37,
        /// <summary>
        /// 169 x 169 Format (QR-Code).
        /// </summary>
        V38,
        /// <summary>
        /// 173 x 173 Format (QR-Code).
        /// </summary>
        V39,
        /// <summary>
        /// 177 x 177 Format (QR-Code).
        /// </summary>
        V40
    }
    /// <summary>
    /// Various types of output.
    /// </summary>
    public enum OutputTypes
    {
        //NOTE: EPS 'disabled because .Net can't produce/handle it.

        /// <summary>
        /// Returns QR-Code encoded text.
        /// </summary>
        /// <remarks>For use with IDAutomation QR-Code or 2D Barcode Fonts.</remarks>
        IDA2DFont,

        /// <summary>
        /// Returns QR-Code native object.
        /// </summary>
        /// <remarks>For use with monospaced fonts.</remarks>
        IDAMonospaceFont,

        /// <summary>
        /// Returns QR-Code native object.
        /// </summary>
        /// <remarks>For use with proportional (standard) fonts.</remarks>
        IDAProportionalFont

    }
}