/*
 * Constants.cs --
 *
 * Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: $
 */

#if ARM || X86 || IA64 || X64
#define HAVE_SIZEOF
#endif

using System;
using System.Threading;
using Eagle._Attributes;
using Eagle._Components.Private;
using Eagle._Components.Public;

#if XML
using Eagle._Containers.Public;
#endif

#if !CONSOLE
using ConsoleColor = Eagle._Components.Public.ConsoleColor;
#endif

namespace Eagle._Constants
{
    [ObjectId("08289e0a-277d-453c-8209-df7e95640e7b")]
    public static class Identifier
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("5f7121e8-6c6b-4c72-8d67-d2e8d57eabce")]
    public static class _String
    {
        public static readonly string Null = "null";
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("0a1a7a70-18fb-4164-b5d9-aebb833e1d75")]
    public static class _Version
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

#if XML
    [ObjectId("19989260-5883-4823-98ee-8a73533b6709")]
    public static class _XmlAttribute
    {
        public static readonly string Id = "id";
        public static readonly string Type = "type";
        public static readonly string Name = "name";
        public static readonly string Group = "group";
        public static readonly string Description = "description";
        public static readonly string TimeStamp = "timeStamp";
        public static readonly string PublicKeyToken = "publicKeyToken";
        public static readonly string Signature = "signature";

        ///////////////////////////////////////////////////////////////////////////////////////////

        internal static readonly StringList RequiredList = new StringList(new string[] {
            Id, Type
        });
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("da7b3fc1-24f5-4a2a-8f9e-deda241ddb15")]
    public static class Xml
    {
        //
        // NOTE: The name of the resource stream that contains our XML schema
        //       data.
        //
        public static readonly string SchemaResourceName =
            GlobalState.GetPackageName(null, ".xsd", false);

        //
        // NOTE: The name of our XML namespace.
        //
        public static readonly string NamespaceName =
            GlobalState.GetPackageNameNoCase();

        //
        // NOTE: The URI of our XML namespace.
        //
        public static readonly Uri NamespaceUri =
            GlobalState.GetAssemblyNamespaceUri();

        //
        // NOTE: The candidate XPath queries used to extract [script] blocks
        //       from an XML document.  The first one that returns some nodes
        //       wins.
        //
        public static readonly StringList XPathList = new StringList(new string[] {
            //
            // NOTE: First, check for the necessary elements using the name of
            //       our namespace.
            //
            (NamespaceName != null) ?
                "//" + NamespaceName + ":blocks/" + NamespaceName + ":block" : null,

            //
            // NOTE: Second, check for the necessary elements using the default
            //       namespace.
            //
            "//blocks/block",

            //
            // NOTE: These list elements are reserved for future use by Eagle.
            //       Please do not change them.
            //
            null,
            null,
            null,
            null,

            //
            // NOTE: These list elements are reserved for use by the user or
            //       application (i.e. to facilitate ease of integration).
            //
            null,
            null,
            null,
            null
        });
    }
#endif

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("51f47a43-205f-4241-931a-e072256719be")]
    public static class Index
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("ab498ee2-f654-404e-b2df-4af7c5482bb1")]
    public static class Level
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("17cc4b98-cdf3-4a73-ada6-3c8dcf34d9ad")]
    public static class Count
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("8630da9a-e4f9-40f3-ab61-10201f8007ca")]
    public static class Percent
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("710e4bb2-28a1-439a-ba12-9e91f3d93ff4")]
    public static class _ConsoleColor
    {
        public static readonly ConsoleColor None = (ConsoleColor)HostColor.None;
        public static readonly ConsoleColor Invalid = (ConsoleColor)HostColor.Invalid;
        public static readonly ConsoleColor Default = (ConsoleColor)HostColor.None;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

#if NATIVE
    [ObjectId("03fcde0a-0800-4f49-8462-dddbd66bf90f")]
    public static class DllName
    {
#if WINDOWS
#if !MONO
        //
        // NOTE: This is the file name for the "Microsoft COM Object Runtime Execution Engine"
        //       and it should be available on the real .NET Framework (all versions).  This is
        //       not available on Mono.
        //
        public const string MsCorEe = "mscoree.dll";
#endif

        public const string MsVcRt = "msvcrt.dll";
        public const string AdvApi32 = "advapi32.dll";
        public const string AdvPack = "advpack.dll";
        public const string Crypt32 = "crypt32.dll";
        public const string Kernel32 = "kernel32.dll";
        public const string NtDll = "ntdll.dll";
        public const string Shell32 = "shell32.dll";
        public const string User32 = "user32.dll";
        public const string WinTrust = "wintrust.dll";
#endif

        public const string Utility = "spilornis.dll";

#if UNIX
        public const string Internal = "__Internal";
        public const string LibC = "libc";
        public const string LibDL = "libdl";
#endif
    }
#endif

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("4adf4145-56a6-4540-987c-2447543eba40")]
    public static class WaitResult
    {
        public static readonly int Object0 = 0x0;
        public static readonly int Abandoned0 = 0x80;
        public static readonly int IoCompletion = 0xC0;
        public static readonly int Timeout = 0x102;
        public static readonly int Failed = unchecked((int)0xFFFFFFFF);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("68a277d1-fb1b-4bbb-8d45-140e80ef0e3f")]
    public static class _Timeout
    {
        public static readonly int Infinite = Timeout.Infinite;
        public static readonly int None = 0;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("0407ec6f-852f-4d02-add6-36fdf51fedad")]
    public static class Width
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("27c8ffcc-9656-4a55-912a-e68f5fb5bcfc")]
    public static class Length
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("54455e76-14fc-4fb1-bfec-6273b550fefa")]
    public static class _Position
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("cab82601-534e-4c1b-8555-c936e8dc6f73")]
    public static class _Size
    {
        public static readonly int Invalid = -1;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("ff56c130-734d-4a3d-9dc1-f38d3c02a144")]
    public static class Port
    {
        public static readonly int Invalid = -1;
        public static readonly int Automatic = 0; // for clients.
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("5cd54e77-bd26-402f-8556-17a9820cd1e1")]
    public static class _Path
    {
        public static readonly string Current = ".";
        public static readonly string Parent = "..";

        public static readonly string Plugins = "Plugins";
        public static readonly string BuildTasks = "BuildTasks";
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("c9f38457-538c-4dfc-8e16-a1b8f3d6c03a")]
    public static class FileName
    {
        public static readonly string Initialization =
            FormatOps.ScriptTypeToFileName(ScriptTypes.Initialization, false);

        public static readonly string Embedding =
            FormatOps.ScriptTypeToFileName(ScriptTypes.Embedding, false);

        public static readonly string Vendor =
            FormatOps.ScriptTypeToFileName(ScriptTypes.Vendor, false);

        public static readonly string Safe =
            FormatOps.ScriptTypeToFileName(ScriptTypes.Safe, false);

        public static readonly string Shell =
            FormatOps.ScriptTypeToFileName(ScriptTypes.Shell, false);

        public static readonly string Test =
            FormatOps.ScriptTypeToFileName(ScriptTypes.Test, false);

        public static readonly string PackageIndex =
            FormatOps.ScriptTypeToFileName(ScriptTypes.PackageIndex, false);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("990c369f-41ee-4f5a-b71e-900d48676b10")]
    public static class ContentType
    {
        public static readonly string Text = "text/plain";

        public static readonly string[] Scripts = {
            "text/x-" + GlobalState.GetPackageNameNoCase(),
            "application/x-" + GlobalState.GetPackageNameNoCase(),
            "text/x-script." + GlobalState.GetPackageNameNoCase()
        };

        public static readonly string Script = Scripts[0];
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("8f0c1c60-0e47-4f19-a3d7-8d6f56348946")]
    public static class FileExtension
    {
        public static readonly string Arguments = ".args";
        public static readonly string Icon = ".ico";
        public static readonly string Profile = ".ini";
        public static readonly string Markup = ".xml";
        public static readonly string Symbols = ".pdb";
        public static readonly string StrongNameKey = ".snk";

        public static readonly string Script =
            GlobalState.GetPackageName(Characters.Period.ToString(), null, true);
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("a263fc47-65e8-4b95-979b-b47b53629df9")]
    internal static class ColorName
    {
        public static readonly string Banner = "Banner";
        public static readonly string Default = "Default";
        public static readonly string Help = "Help";
        public static readonly string HelpItem = "HelpItem";
        public static readonly string Legal = "Legal";
        public static readonly string Official = "Official";
        public static readonly string Unofficial = "Unofficial";
        public static readonly string Trusted = "Trusted";
        public static readonly string Untrusted = "Untrusted";
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("3ea126e0-52f7-4b34-8e80-d428da5c9d8b")]
    internal static class StandardChannel
    {
        public static readonly string Input = Channel.StdIn;
        public static readonly string Output = Channel.StdOut;
        public static readonly string Error = Channel.StdErr;
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

#if SHELL
    [ObjectId("99951710-f239-43e3-9cea-92fdc4d1d18b")]
    internal static class CommandLineArgument
    {
        public static readonly string StandardInput = "-";
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("656078c8-4735-42ca-a6fe-55eb72502a17")]
    internal static class CommandLineOption
    {
        public static readonly string AnyInitialize = "anyInitialize";
        public static readonly string Arguments = "arguments";
        public static readonly string Break = "break";
        public static readonly string Debug = "debug";
        public static readonly string Encoding = "encoding";
        public static readonly string Evaluate = "evaluate";
        public static readonly string EvaluateEncoded = "evaluateEncoded";
        public static readonly string File = "file";
        public static readonly string Help = "help";
        public static readonly string About = "?";
        public static readonly string CommandHelp = "??";
        public static readonly string EnvironmentHelp = "???";
        public static readonly string ForceInitialize = "forceInitialize";
        public static readonly string FullHelp = "????";
        public static readonly string Initialize = "initialize";
        public static readonly string Interactive = "interactive";
        public static readonly string Library = "library";
        public static readonly string Namespaces = "namespaces";
        public static readonly string NoArgumentsFileName = "noArgumentsFileName";
        public static readonly string NoExit = "noExit";
        public static readonly string NoTrace = "noTrace";
        public static readonly string Pause = "pause";
        public static readonly string PluginArguments = "pluginArguments";
        public static readonly string PostFile = "postFile";
        public static readonly string PostInitialize = "postInitialize";
        public static readonly string PreFile = "preFile";
        public static readonly string PreInitialize = "preInitialize";
        public static readonly string Profile = "profile";
        public static readonly string Reconfigure = "reconfigure";
        public static readonly string RuntimeOption = "runtimeOption";
        public static readonly string Safe = "safe";
        public static readonly string SetLoop = "setLoop";
        public static readonly string SetInitialize = "setInitialize";
        public static readonly string Standard = "standard";
        public static readonly string Step = "step";
        public static readonly string Test = "test";
        public static readonly string PluginTest = "pluginTest";
        public static readonly string TestDirectory = "testDirectory";
        public static readonly string Trace = "trace";
        public static readonly string TraceToHost = "traceToHost";
        public static readonly string VendorPath = "vendorPath";
        public static readonly string Version = "version";
    }
#endif

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("6475066f-5f77-49c0-bcc0-177abe8cf24a")]
    public static class Prompt
    {
        public static readonly string Namespaces =
            "Namespace support {0}.";

        public static readonly string NoArgumentsFileName =
            "Arguments file name processing skipped.";

        public static readonly string NoExit =
            "Interactive loop will be entered.";

        public static readonly string Debugger =
            "Attach a debugger to process {0} and press any key to continue.";

        public static readonly string Interactive =
            "Interactive mode enabled.";

        public static readonly string PluginArguments =
            "Arguments added for plugin: {0}.";

        public static readonly string LibraryPath =
            "Script library path was overridden.";

        public static readonly string SingleStep =
            "Script debugger single-step enabled.";

        public static readonly string NoDebugger =
            "Script debugger not available.";

        public static readonly string CreateFlags =
            "Interpreter creation flags overridden via environment: {0}.";

        public static readonly string InterpreterFlags =
            "Interpreter instance flags overridden via environment: {0}.";

        public static readonly string Console =
            "Console enabled.";

        public static readonly string NoConsole =
            "Console disabled.";

        public static readonly string Debug =
            "Debug mode enabled.";

        // public static readonly string Verbose =
        //     "Verbose mode enabled.";

        public static readonly string NoTrace =
            "Tracing disabled.";

        public static readonly string Trace =
            "Tracing enabled.";

        public static readonly string NoTrusted =
            "Executable file certificate trust checking disabled.";

        public static readonly string NoVerified =
            "Assembly strong name signature verification disabled.";

        public static readonly string Quiet =
            "Quiet mode enabled.";

        public static readonly string DefaultQuiet =
            "Default quiet mode enabled.";

        public static readonly string DefaultTraceStack =
            "Default tracing of managed call stack enabled.";

        public static readonly string NoVerbose =
            "Selected diagnostic messages are disabled.";

        public static readonly string UtilityPath =
            "Utility path overridden via environment: {0}.";

        public static readonly string VendorPath =
            "Vendor path overridden via environment: {0}.";

        public static readonly string EllipsisLimit =
            "Ellipsis limit overridden via environment: {0}.";

        public static readonly string Throw =
            "Re-throwing of unhandled exceptions enabled.";

        public static readonly string NeverGC =
            "Internal calls to collect garbage always disabled.";

        public static readonly string NeverWaitForGC =
            "Internal waits for pending finalizers always disabled.";

        public static readonly string AlwaysWaitForGC =
            "Internal waits for pending finalizers always enabled.";

        public static readonly string TraceToHost =
            "Tracing to host enabled.";

        public static readonly string TraceError =
            "Tracing cannot be enabled: {0}.";

        public static readonly string DebugTrace =
            "Debug tracing enabled.";

        public static readonly string DebugTraceError =
            "Debug tracing cannot be enabled: {0}.";

        public static readonly string ForceInitialize =
            "Script library initialization will be forced.";

        public static readonly string Initialize =
            "Script library initialization will be enabled.";

        public static readonly string NoInitialize =
            "Script library initialization will be skipped.";

        public static readonly string Loop =
            "Interactive loop will be enabled.";

        public static readonly string NoLoop =
            "Interactive loop will be skipped.";

        public static readonly string NoThrowOnDisposed =
            "Exceptions will not be thrown when disposed objects are accessed.";

        public static readonly string Profile =
            "Host profile set to \"{0}\".";

        public static readonly string UseAttach =
            "Console will be attached or opened.";

        public static readonly string NoColor =
            "Console output will not be in color.";

        public static readonly string NoTitle =
            "Console title will not be changed.";

        public static readonly string NoUtility =
            "Native utility library will not be loaded.";

        public static readonly string NoIcon =
            "Console icon will not be changed.";

        public static readonly string NoProfile =
            "Host profile will not be loaded.";

        public static readonly string NoCancel =
            "Host script cancellation interface will not be enabled.";

        public static readonly string Safe =
            "Safe mode enabled.";

        public static readonly string Standard =
            "Standard mode enabled.";
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("332b7844-2734-4413-b835-704abe7547c1")]
    public static class PublicKeyToken
    {
        //
        // NOTE: Most of the ECMA compliant parts of the CLR use this
        //       public key token.
        //
        public static readonly string Ecma = "b77a5c561934e089"; // MS

        //
        // NOTE: Most of the Microsoft specific extensions to the CLR
        //       use this public key token.
        //
        public static readonly string Clr = "b03f5f7f11d50a3a";  // MS

        //
        // NOTE: The Visual C++ runtime libraries use this public key
        //       token; however, only the managed C++ assemblies (e.g.
        //       "msvcm??.dll") are actually signed with it (i.e. the
        //       pure native libraries are not actually signed with
        //       it).
        //
        public static readonly string Vc = "1fc8b3b9a1e18e3b";   // MS

        //
        // NOTE: Official debug builds (whether public or private) of
        //       the Eagle runtime library are signed with this public
        //       key token ("EagleFastPublic.snk", 4096 bits).
        //
        public static readonly string Fast = "29c6297630be05eb";

        //
        // NOTE: Official public release builds of the Eagle runtime
        //       library are signed with this public key token
        //       ("EagleStrongPublic.snk", 16384 bits).
        //
        public static readonly string Strong = "1e22ec67879739a2";

        //
        // NOTE: Official pre-release builds of the Eagle runtime
        //       library may be signed with this public key token
        //       ("EagleBetaPublic.snk", 8200 bits).
        //
        public static readonly string Beta = "358030063a832bc3";
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("792c2824-1549-4ad2-919f-f58c7c4455ae")]
    public static class PublicKey
    {
        //
        // NOTE: All builds (whether public or private) of the Eagle
        //       runtime library WILL trust and use this key for
        //       checking for and/or installing updates to itself.
        //
        //       This key MAY also be used to sign release builds.
        //
        public static readonly byte[] SoftwareUpdate1 = {
            0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01,
            0x00, 0xd1, 0x21, 0x9f, 0xbe, 0x43, 0x9d, 0xb6,
            0xc7, 0x65, 0xe6, 0xb4, 0x54, 0x35, 0xd1, 0x70,
            0xec, 0x62, 0x6c, 0x20, 0xc2, 0xaa, 0x42, 0x30,
            0xcd, 0x1e, 0x0e, 0x6f, 0x98, 0xf9, 0x08, 0x05,
            0x41, 0x2a, 0x29, 0x13, 0xc0, 0xb4, 0x9b, 0x47,
            0x42, 0xe3, 0x6e, 0xfc, 0x6d, 0x6d, 0x6e, 0xbb,
            0x56, 0x23, 0xda, 0xaa, 0x39, 0xeb, 0x83, 0x36,
            0x95, 0xd6, 0x66, 0x81, 0xed, 0x0c, 0x3a, 0xd0,
            0x53, 0x62, 0x09, 0xb6, 0x1c, 0x8b, 0xbd, 0x74,
            0x07, 0xfc, 0x2d, 0x88, 0x8f, 0x0f, 0x46, 0x62,
            0x19, 0xa3, 0x69, 0x7b, 0x52, 0x57, 0xbe, 0x32,
            0x64, 0xae, 0xd2, 0xef, 0xb9, 0x32, 0x85, 0x31,
            0x46, 0x2e, 0xb5, 0x77, 0x18, 0x62, 0x69, 0xf0,
            0xd2, 0xd0, 0xe0, 0x7a, 0x1a, 0x08, 0xc1, 0x9d,
            0x07, 0xe4, 0x70, 0x08, 0xf3, 0xdd, 0xa5, 0xa5,
            0x38, 0x70, 0xfc, 0xce, 0xaa, 0xc1, 0x80, 0x41,
            0x1a, 0x64, 0xe9, 0xa0, 0x1d, 0x1c, 0x55, 0x30,
            0xea, 0x18, 0xee, 0x44, 0x0f, 0xdc, 0x5a, 0xcd,
            0x00, 0xc5, 0xc3, 0x9b, 0x76, 0x95, 0x87, 0x32,
            0x0d, 0x7d, 0x00, 0x72, 0x53, 0x64, 0x38, 0xde,
            0xc2, 0x01, 0x58, 0x02, 0xe3, 0x50, 0x3e, 0xf1,
            0xb3, 0x1b, 0x89, 0x01, 0x05, 0x40, 0x50, 0xe4,
            0x5d, 0xef, 0x14, 0xb4, 0xf3, 0x89, 0x52, 0x09,
            0x46, 0x74, 0xb3, 0x49, 0x33, 0x37, 0x41, 0x50,
            0xef, 0x18, 0x77, 0x0f, 0x15, 0x93, 0x78, 0xdd,
            0xda, 0x9a, 0xbb, 0x73, 0xfe, 0xa9, 0xa8, 0xe1,
            0x31, 0xd8, 0xf8, 0xbe, 0x27, 0xf1, 0xcd, 0x7b,
            0x1d, 0xb7, 0xd1, 0x9a, 0xfb, 0xdc, 0xc1, 0xa2,
            0x5f, 0x68, 0x9a, 0x54, 0x28, 0x19, 0x55, 0x36,
            0xd3, 0xdd, 0x1b, 0xb9, 0x10, 0x8e, 0x8e, 0x88,
            0xaa, 0xe5, 0x55, 0x4b, 0x42, 0xf9, 0x14, 0x8c,
            0xbd, 0x43, 0xd4, 0x32, 0x8a, 0xe6, 0x70, 0x0a,
            0xe7, 0x02, 0x03, 0x01, 0x00, 0x01
        };
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////

    [ObjectId("c094f589-7ec2-4494-9cc0-498ea9fe2926")]
    public static class Build
    {
#if IA64 || X64
        public const int SizeOfIntPtr = 8;
#elif ARM || X86
        public const int SizeOfIntPtr = 4;
#else
        // #warning "Preprocessor define for ARM, X86, X64, or IA64 should be present."
#endif

#if DEBUG
        public static readonly bool Debug = true;
#else
        public static readonly bool Debug = false;
#endif
    }
}
