///Licensed under Creative Commons Attribution 4.0 License, Written by Clemens Winter and Vladislav Nachev
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml.Packaging;
using System.Globalization;

namespace Exploitation
{
    /// <summary>
    /// Reads the flower data from given file (e.g. ~\Exploit\Exploitation\Flower Bat World\Flowers.xslx)
    /// Further instructions in the file.
    /// </summary>
    class CreateFlowers : CreateRessources
    {
        string subDir, filename, ressourcenTable;



        public CreateFlowers(string subDir, string filename, string table)
        {
            this.subDir   = subDir;
            this.filename = filename;
            ressourcenTable = table; 
        }


        public RessourceManager CreateRessources()
        {

            NumberFormatInfo info = new CultureInfo("en-US", false).NumberFormat;  // -> suppress US Format
            SpreadsheetDocument spreadsheet = SpreadsheetDocument.Open(subDir + "//" + filename, false);
            Table ressourcesTable = spreadsheet.Table(ressourcenTable);


            List<Flower> flowerList = new List<Flower>();
            int id = 0;

            foreach (var r in ressourcesTable.TableRows())

            {
                flowerList.Add(new Flower(id++,
                                          Int32.Parse(r["x"].Value),
                                          Int32.Parse(r["y"].Value),
                                          Int32.Parse(r["z"].Value),
                                          double.Parse(r["nectarSugarSecretion"].Value),
                                          double.Parse(r["nectarAccount"].Value),
                                          int.Parse(r["nectarMaxAccount"].Value),
                                          r["genotype"].Value,
                                          double.Parse(r["concentration"].Value),
                                          int.Parse(r["type"].Value),
                                          r["vol1"].Value,
                                          double.Parse(r["vol1probability"].Value),
                                          double.Parse(r["vol2"].Value),
                                          double.Parse(r["vol2probability"].Value)
                                          ));

            }

            return new FlowerManager(flowerList.ToArray());
        }

       
    }
}
