﻿using OREM_STAT.ViewModel;
using System;
using System.Collections.Generic;

namespace OREM_STAT
{
    internal static class Extension
    {
        public static DateTime? GetParent(this DateTime Period, PeriodType pType)
        {
            switch (pType)
            {
                case PeriodType.Year:
                    {
                        return null;
                    }
                case PeriodType.Month:
                    {
                        return new DateTime?(new DateTime(Period.Year, 1, 1));
                    }
                case PeriodType.Day:
                    {
                        return new DateTime(Period.Year, Period.Month, 1, 0, 0, 0);
                    }
                case PeriodType.Hour:
                    {
                        return new DateTime(Period.Year, Period.Month, Period.Day, 0, 0, 0);
                    }
                case PeriodType.HalfHour:
                    {
                        return new DateTime(Period.Year, Period.Month, Period.Day, Period.Hour, 0, 0);
                    }
            }
            return null;
        }

        public static List<DateTime> GetChilds(this DateTime Period, PeriodType pType)
        {
            List<DateTime> res = new List<DateTime>();
            switch (pType)
            {
                case PeriodType.Year:
                    {
                        for (int i = 1; i <= 12; i++)
                        {
                            res.Add(new DateTime(Period.Year, i, 1));  
                        }
                        return res;
                    }
                case PeriodType.Month:
                    {
                        for (int i = 1; i <= DateTime.DaysInMonth(Period.Year, Period.Month); i++)
                        {
                            res.Add(new DateTime(Period.Year, Period.Month, i));
                        }
                        return res;
                    }
                case PeriodType.Day:
                    {
                        for (int i = 0; i <= 23; i++)
                        {
                            res.Add(new DateTime(Period.Year, Period.Month, Period.Day, i, 0, 0));
                        }
                        return res;
                    }
                case PeriodType.Hour:
                    {
                        return res;
                    }
                case PeriodType.HalfHour:
                    {
                        return res;
                    }
            }
            return res;
        }
    }
}
