using System;
using Baza_Reklam.Classes.Model;

namespace Baza_Reklam.Classes.Helpers
{
    public struct AdSize
    {
        public int Width;
        public int Height;
    }

    public class AdHelper
    {
        //TODO: get the initial ad size, margin size and max width height from db
        public static AdSize GetAdSize(int horizontal, int vertical, Module module)
        {
            AdSize adSize = new AdSize();

            if (!EnableModuleCount(module))
            {
                adSize.Width = Convert.ToInt32(module.Width);
                adSize.Height = Convert.ToInt32(module.Height);
                return adSize;
            }

            int width = 0;
            int height = 0;

            if (module.Section.Title.ShortName == "AMT")
            {
                if (module.Section.Name.ToUpper() == "ZOOM")
                {
                    //max 5 x 6
                    width = ((horizontal - 1) * 3) + (horizontal * 45);
                    height = Convert.ToInt32(((vertical - 1) * 3) + (vertical * 50.33));
                }
                else
                {
                    //max 8 x 8
                    width = ((horizontal - 1) * 3) + (horizontal * 27);
                    height = ((vertical - 1) * 3) + (vertical * 37);
                }
            }
            else if (module.Section.Title.ShortName == "GS")
            {
                //max 3 x 4
                width = ((horizontal - 1) * 3) + (horizontal * 67);
                height = ((vertical - 1) * 3) + (vertical * 65);
            }

            
            adSize.Width = width;
            adSize.Height = height;
            return adSize;
        }

        public static bool EnableModuleCount(Module module)
        {
            switch (module.Section.Title.ShortName)
            {
                case "GS":
                    return EnableGsModuleCount(module);
                case "adMot":
                    return EnableAdMotoModuleCount(module);
                default:
                    return EnableAmtModuleCount(module);
            }
        }

        //TODO: get this info from db, IsSplitable...?
        private static bool EnableAmtModuleCount(Module module)
        {
            switch (module.Name)
            {
                case "AWEB":
                case "AWEF":
                case "ALAF":
                case "AZOF":
                    return true;
            }

            return false;
        }

        //TODO: get this info from db, IsSplitable...?
        private static bool EnableGsModuleCount(Module module)
        {
            switch (module.Name)
            {
                case "GOK1M":
                //case "GOK2":
                case "GOK3M":
                //case "GOK4":
                case "GWEW_P":
                case "GWEW":
                    //case "GART_S":
                    return true;
            }

            return false;
        }

        //TODO: get this info from db, IsSplitable...?
        private static bool EnableAdMotoModuleCount(Module module)
        {
            switch (module.Name)
            {
                case "ad-Text":
                case "Truck-Text":
                    return true;
            }

            return false;
        }

    }
}