// ----------------------------------------------------------------------------------
// Microsoft Developer & Platform Evangelism
// 
// Copyright (c) Microsoft Corporation. All rights reserved.
// 
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// ----------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
// ----------------------------------------------------------------------------------

namespace Microsoft.Samples.WindowsAzureMmc.SnapIn
{
    using System;
    using System.Collections.Generic;
    using System.Management.Automation;
    using System.Management.Automation.Host;
    using System.Security;

    public class WindowsPSHostUserInterface : PSHostUserInterface
    {
        private string account = string.Empty;
        private string key = string.Empty;

        public WindowsPSHostUserInterface(string account, string key)
        {
            this.account = account;
            this.key = key;
        }

        #region LowLevel UI Interface
        public override PSHostRawUserInterface RawUI
        {
            get { return null; }
        }
        #endregion

        #region User prompt Methods
        public override Dictionary<string, System.Management.Automation.PSObject> Prompt(string caption, string message, System.Collections.ObjectModel.Collection<FieldDescription> descriptions)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override int PromptForChoice(string caption, string message, System.Collections.ObjectModel.Collection<ChoiceDescription> choices, int defaultChoice)
        {
            return 0;
        }

        public override System.Management.Automation.PSCredential PromptForCredential(string caption, string message, string userName, string targetName)
        {
            SecureString secureKey = new SecureString();
            foreach (char ch in this.key)
            { 
                secureKey.AppendChar(ch); 
            }

            PSCredential cred = new PSCredential(this.account, secureKey);
            return cred;
        }

        public override System.Management.Automation.PSCredential PromptForCredential(string caption, string message, string userName, string targetName, System.Management.Automation.PSCredentialTypes allowedCredentialTypes, System.Management.Automation.PSCredentialUIOptions options)
        {
            SecureString secureKey = new SecureString();
            foreach (char ch in this.key)
            {
                secureKey.AppendChar(ch);
            }

            PSCredential cred = new PSCredential(this.account, secureKey);
            return cred;
        }
        #endregion

        #region powershell writeXXXX methods
        public override void Write(string value)
        {
            // do nothing
        }

        public override void Write(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
        {
            // do nothing
        }

        public override void WriteDebugLine(string message)
        {
            // do nothing
        }

        public override void WriteErrorLine(string value)
        {
            // do nothing
        }

        public override void WriteLine()
        {
            // do nothing
        }

        public override void WriteLine(string value)
        {
            // do nothing
        }

        public override void WriteLine(ConsoleColor foregroundColor, ConsoleColor backgroundColor, string value)
        {
            // do nothing
        }

        public override void WriteProgress(long sourceId, System.Management.Automation.ProgressRecord record)
        {
            // do nothing
        }

        public override void WriteVerboseLine(string message)
        {
            // do nothing
        }

        public override void WriteWarningLine(string message)
        {
            // do nothing
        }
        #endregion

        #region ReadXXX methods
        public override string ReadLine()
        {
            throw new Exception("The method or operation is not implemented.");
        }

        public override System.Security.SecureString ReadLineAsSecureString()
        {
            throw new Exception("The method or operation is not implemented.");
        }
        #endregion
    }
}