using GMW_data;
using SteamWare;
using System.Collections.Generic;
using System.Web.Script.Services;
using System.Web.Services;

namespace GMW.WS
{
    /// <summary>
    /// Summary description for WS_Data
    /// </summary>
    [WebService(Namespace = "http://www.steamware.net/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class DataFeed : System.Web.Services.WebService
    {

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string[] test(string prefixText)
        {
            //TODO: implement real search here!
            // dummy implementation
            List<string> output = new List<string>();
            for (int i = 0; i < 100; i++)
            {
                output.Add(string.Format("{0}{1}#{1}", prefixText, i));
            }
            return output.ToArray();
        }

        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string[] celle(string prefixText)
        {
            // inizializzo risposta
            List<string> suggerimenti = new List<string>();
            // proseguo SOLO SE min "MinCharAutocomplete" char...
            if (prefixText.Length >= memLayer.ML.cdvi("MinCharAutocomplete"))
            {
                // elenco candidati
                DS_magazzino.CelleDataTable tabCelle = MagClass.magazzino.taCelle.getByCodCellaLike(prefixText, memLayer.ML.cdv("CodCS"));
                // aggiungo ogni riga...
                foreach (DS_magazzino.CelleRow riga in tabCelle)
                {
                    suggerimenti.Add(string.Format("{0}#{1}", riga.CodCella, riga.CodCella));
                }
            }
            return suggerimenti.ToArray();
        }
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string[] particolari(string prefixText)
        {
            // inizializzo risposta
            List<string> suggerimenti = new List<string>();
            // proseguo SOLO SE min "MinCharAutocomplete" char...
            if (prefixText.Length >= memLayer.ML.cdvi("MinCharAutocomplete"))
            {
                // elenco candidati
                GMW_data.DS_Utility.v_selParticolariDataTable tabParticolari = utils.obj.taSelPart.getByConditioPref("P", prefixText);
                // aggiungo ogni riga...
                foreach (GMW_data.DS_Utility.v_selParticolariRow riga in tabParticolari)
                {
                    suggerimenti.Add(string.Format("{0}#{1}", riga.value, riga.value));
                }
            }
            return suggerimenti.ToArray();
        }
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public string[] anime(string prefixText)
        {
            // inizializzo risposta
            List<string> suggerimenti = new List<string>();
            // proseguo SOLO SE min "MinCharAutocomplete" char...
            if (prefixText.Length >= memLayer.ML.cdvi("MinCharAutocomplete"))
            {
                // elenco candidati
                GMW_data.DS_Utility.v_selParticolariDataTable tabParticolari = utils.obj.taSelPart.getByConditioPref("A", prefixText);
                // aggiungo ogni riga...
                foreach (GMW_data.DS_Utility.v_selParticolariRow riga in tabParticolari)
                {
                    suggerimenti.Add(string.Format("{0}#{1}", riga.value, riga.value));
                }
            }
            return suggerimenti.ToArray();
        }

    }
}
