{{#if copyright.claimant}}
/*
All the code that follow is
Copyright (c) {{copyright.year}}, {{copyright.claimant}}. All Rights Reserved.
Not for reuse without permission.
*/

{{/if}}
using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;

{{#if model.namespace}}namespace {{model.namespace}}
{
{{/if}}
{{#if model.namespace}}    {{/if}}public class {{model.name}}
{{#if model.namespace}}    {{/if}}{
{{#if model.namespace}}    {{/if}}    private Dictionary<string, string> data;
{{#if model.namespace}}    {{/if}}    private IWebDriver driver;
{{#if model.namespace}}    {{/if}}    private int timeout = {{timeout}};

        {{#attributes}}
        {{#if attribute.strategy}}
{{#if @root.model.namespace}}    {{/if}}    [FindsBy(How = How.{{proper attribute.strategy}}{{#equals attribute.strategy 'css'}}Selector{{/equals}}, Using = "{{{attribute.value}}}")]
{{#if @root.model.namespace}}    {{/if}}    [CacheLookup]
{{#if @root.model.namespace}}    {{/if}}    private {{#equals type 'radio'}}IList<IWebElement>{{else}}IWebElement{{/equals}} {{attribute.name}};
        {{else}}
{{#if @root.model.namespace}}    {{/if}}    private readonly string {{attribute.name}} = "{{{attribute.value}}}";
        {{/if}}
        {{/attributes}}

{{#if model.namespace}}    {{/if}}    public {{model.name}}()
{{#if model.namespace}}    {{/if}}        : this(default(IWebDriver), new Dictionary<string, string>(), {{timeout}})
{{#if model.namespace}}    {{/if}}    {
{{#if model.namespace}}    {{/if}}    }

{{#if model.namespace}}    {{/if}}    public {{model.name}}(IWebDriver driver)
{{#if model.namespace}}    {{/if}}        : this(driver, new Dictionary<string, string>(), {{timeout}})
{{#if model.namespace}}    {{/if}}    {
{{#if model.namespace}}    {{/if}}    }

{{#if model.namespace}}    {{/if}}    public {{model.name}}(IWebDriver driver, Dictionary<string, string> data)
{{#if model.namespace}}    {{/if}}        : this(driver, data, {{timeout}})
{{#if model.namespace}}    {{/if}}    {
{{#if model.namespace}}    {{/if}}    }

{{#if model.namespace}}    {{/if}}    public {{model.name}}(IWebDriver driver, Dictionary<string, string> data, int timeout)
{{#if model.namespace}}    {{/if}}    {
{{#if model.namespace}}    {{/if}}        this.driver = driver;
{{#if model.namespace}}    {{/if}}        this.data = data;
{{#if model.namespace}}    {{/if}}        this.timeout = timeout;
{{#if model.namespace}}    {{/if}}    }

        {{#operations}}
{{#if @root.model.namespace}}    {{/if}}    /// <summary>
{{#if @root.model.namespace}}    {{/if}}    /// {{#if argument}}{{argument.documentation}}{{else}}{{operation.documentation}}{{/if}}
{{#if @root.model.namespace}}    {{/if}}    /// </summary>
{{#if @root.model.namespace}}    {{/if}}    /// <returns>The {{default target.modelName @root.model.name}} class instance.</returns>
{{#if @root.model.namespace}}    {{/if}}    public {{default target.modelName @root.model.name}} {{operation.name}}() 
{{#if @root.model.namespace}}    {{/if}}    {
        {{#if argument}}
        {{#unequals type 'radio'}}
{{#if @root.model.namespace}}    {{/if}}        return {{operation.name}}(data["{{argument.key}}"]);
{{#if @root.model.namespace}}    {{/if}}    }

{{#if @root.model.namespace}}    {{/if}}    /// <summary>
{{#if @root.model.namespace}}    {{/if}}    /// {{operation.documentation}}
{{#if @root.model.namespace}}    {{/if}}    /// </summary>
{{#if @root.model.namespace}}    {{/if}}    /// <returns>The {{default target.modelName @root.model.name}} class instance.</returns>
{{#if @root.model.namespace}}    {{/if}}    public {{default target.modelName @root.model.name}} {{operation.name}}(string {{argument.name}})
{{#if @root.model.namespace}}    {{/if}}    {
        {{/unequals}}
        {{/if}}
        {{#equals type 'button'}}
{{#if @root.model.namespace}}    {{/if}}        {{attribute.name}}.Click();
        {{/equals}}
        {{#equals type 'checkbox'}}
{{#if @root.model.namespace}}    {{/if}}        if ({{#unless negate}}!{{/unless}}{{attribute.name}}.Selected) {
{{#if @root.model.namespace}}    {{/if}}            {{attribute.name}}.Click();
{{#if @root.model.namespace}}    {{/if}}        }
        {{/equals}}
        {{#equals type 'fill'}}
        {{#fill}}
{{#if @root.model.namespace}}    {{/if}}        {{operation.name}}();
        {{/fill}}
        {{/equals}}
        {{#equals type 'fill.submit'}}
{{#if @root.model.namespace}}    {{/if}}        Fill();
{{#if @root.model.namespace}}    {{/if}}        return Submit();
        {{/equals}}
        {{#equals type 'link'}}
{{#if @root.model.namespace}}    {{/if}}        {{attribute.name}}.Click();
        {{/equals}}
        {{#equals type 'radio'}}
{{#if @root.model.namespace}}    {{/if}}        foreach (IWebElement el in {{attribute.name}}) {
{{#if @root.model.namespace}}    {{/if}}            if (el.GetAttribute("value").Equals({{argument.name}})) {
{{#if @root.model.namespace}}    {{/if}}                if (!el.Selected) {
{{#if @root.model.namespace}}    {{/if}}                    el.Click();
{{#if @root.model.namespace}}    {{/if}}                }
{{#if @root.model.namespace}}    {{/if}}                break;
{{#if @root.model.namespace}}    {{/if}}            }
{{#if @root.model.namespace}}    {{/if}}        }
        {{/equals}}
        {{#equals type 'select'}}
{{#if @root.model.namespace}}    {{/if}}        new SelectElement({{attribute.name}}).{{#if negate}}Des{{else}}S{{/if}}electByText({{argument.name}});
        {{/equals}}
        {{#equals type 'submit'}}
{{#if @root.model.namespace}}    {{/if}}        {{target.name}}();
            {{#if target.modelName}}
{{#if @root.model.namespace}}    {{/if}}        {{target.modelName}} target = new {{target.modelName}}(driver, data, timeout);
{{#if @root.model.namespace}}    {{/if}}        PageFactory.InitElements(driver, target);
            {{/if}}
        {{/equals}}
        {{#equals type 'text'}}
{{#if @root.model.namespace}}    {{/if}}        {{attribute.name}}.SendKeys({{argument.name}});
        {{/equals}}
        {{#equals type 'verify.loaded'}}
{{#if @root.model.namespace}}    {{/if}}        new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)).Until<bool>((d) =>
{{#if @root.model.namespace}}    {{/if}}        {
{{#if @root.model.namespace}}    {{/if}}            return d.PageSource.Contains({{attribute.name}});
{{#if @root.model.namespace}}    {{/if}}        });
        {{/equals}}
        {{#equals type 'verify.url'}}
{{#if @root.model.namespace}}    {{/if}}        new WebDriverWait(driver, TimeSpan.FromSeconds(timeout)).Until<bool>((d) =>
{{#if @root.model.namespace}}    {{/if}}        {
{{#if @root.model.namespace}}    {{/if}}            return d.Url.Contains({{attribute.name}});
{{#if @root.model.namespace}}    {{/if}}        });
        {{/equals}}
        {{#unequals type 'fill.submit'}}
{{#if @root.model.namespace}}    {{/if}}        return {{#if target.modelName}}target{{else}}this{{/if}};
        {{/unequals}}
{{#if @root.model.namespace}}    {{/if}}    }
        {{/operations}}
{{#if model.namespace}}    {{/if~}} }
{{#if model.namespace}}
}
{{/if}}
