using ComponentPro;

namespace AdvancedDemo.Samples.Advanced_Sample
{
    class Order_Invoice : TemplateExampleBase
    {
        class OrderProduct
        {
            private int _partId;
            private string _productName;
            private int _quantity;
            private float _price;

            public int PartId
            {
                get { return _partId; }
                set { _partId = value; }
            }

            public string ProductName
            {
                get { return _productName; }
                set { _productName = value; }
            }

            public int Quantity
            {
                get { return _quantity; }
                set { _quantity = value; }
            }

            public float Price
            {
                get { return _price; }
                set { _price = value; }
            }
        }

        class User
        {
            private string _fullName;
            private string _emailAddress;
            private string _password;

            public string FullName
            {
                get { return _fullName; }
                set { _fullName = value; }
            }

            public string EmailAddress
            {
                get { return _emailAddress; }
                set { _emailAddress = value; }
            }

            public string Password
            {
                get { return _password; }
                set { _password = value; }
            }

            public OrderProduct[] GetOrders()
            {
                OrderProduct[] ops = new OrderProduct[3];

                ops[0] = new OrderProduct();
                ops[0].PartId = 1239;
                ops[0].Price = 104.09f;
                ops[0].ProductName = "Product A";
                ops[0].Quantity = 3;

                ops[1] = new OrderProduct();
                ops[1].PartId = 22;
                ops[1].Price = 134.09f;
                ops[1].ProductName = "Product B";
                ops[1].Quantity = 1;

                ops[2] = new OrderProduct();
                ops[2].PartId = 167;
                ops[2].Price = 14.7f;
                ops[2].ProductName = "Product C";
                ops[2].Quantity = 5;

                return ops;
            }
        }


        /// <summary>
        /// Generates output from a template file.
        /// </summary>
        /// <param name="templateSourceDirectory">The path to the directory that contains the template file.</param>
        /// <param name="templateFile">The template file path.</param>
        /// <param name="templateSource">The template source loaded from the template file.</param>
        /// <returns>The generated output.</returns>
        public override string Generate(string templateSourceDirectory, string templateFile, string templateSource)
        {
            // Create a new instance of the TemplateEngine class.
            TemplateEngine dt = new TemplateEngine();

            // Load template content from a file.
            dt.LoadFromString(templateSource);

            dt.SetValue("CompanyName", "My Company Name");

            User u = new User();
            u.EmailAddress = "myemail@somedomain.com";
            u.FullName = "John Borders";
            u.Password = "123abc";
            dt.SetValue("User", u);
            dt.SetValue("OrderId", "1625DGHJ");

            // Generate output.
            string output = dt.Run();

            return output;
        }
    }
}
