using System;
using Kreta.BusinessLogic.Helpers;
using Kreta.Core.ConnectionType;

namespace Kreta.BusinessLogic.HelperClasses
{
    public class TanuloKeresesCO
    {
        private DateTime _lekerdezesNapja = DateTime.Today;
        private DateTime? _tanevElsoNapja = null;
        private DateTime? _tanevUtolsoNapja = null;

        public TanuloKeresesCO(IConnectionType connectionType, bool isAktivTanev)
        {
            var tanevHelper = new TanevHelper(connectionType);
            TanevId = connectionType.TanevId;
            IntezmenyId = connectionType.IntezmenyId;
            var tanev = tanevHelper.GetTanevInfo();
            _tanevElsoNapja = tanev.OraFelvetelKezdete;
            _tanevUtolsoNapja = tanev.UtolsoTanitasiNap; /*nem e jobb lenne itt a sima tanév kezdete vége??*/

            // több besorolás esetén mindig az utolsó osztályt kell megjeleníteni,
            // ezért van szükség erre a dátumra, főleg ha nem aktiv tanévről van szó
            _lekerdezesNapja = tanev.UtolsoTanitasiNap;

            IsAktivTanev = isAktivTanev;
        }

        public string Nev { get; set; }
        public DateTime? SzuletesiIdoKezdet { get; set; }
        public DateTime? SzuletesiIdoVeg { get; set; }
        public string AnyjaNeve { get; set; }
        public string SzuletesiHely { get; set; }
        public int? OsztalyId { get; set; }
        public int? EvfolyamId { get; set; }
        public int? Neme { get; set; }
        public int? FelvetelEve { get; set; }
        public bool Aktiv { get; set; }
        public string Vegzos { get; set; }
        public string SNI { get; set; }
        public string BTM { get; set; }
        public int? FeladatellatasiHelyId { get; set; }
        public int? HatranyosHelyzetId { get; set; }
        public bool Torolt { get; set; } = false;
        public string OktatasiAzonosito { get; set; }
        public bool? OsztalybaSoroltTantervNelkul { get; set; }
        public bool? NincsNem { get; set; }
        public bool? NincsSzakmaCsoport { get; set; }
        public bool? NincsAnyanyelv { get; set; }
        public bool? NincsAllampolgarsag { get; set; }
        public bool? TanuloBelepesNelkul { get; set; }
        public bool? NincsOsztondijAlapAdat { get; set; }
        public bool? NincsOsztondijUtalasAdat { get; set; }
        public bool? VanKettosOsztalybesorolas { get; set; }
        public bool IsHibasanRogzitettOktatasiAzonositok { get; set; }
        public bool IsHibasanRogzitettTajSzamok { get; set; }
        public bool IsHibasanRogzitettAdoazonositoJelek { get; set; }
        public bool IsFromSzervezet { get; set; }
        public int? SzervezetId { get; set; }
        public string SzervezetNev { get; set; }
        public string SzervezetAzonosito { get; set; }
        public int TanevId { get; set; }
        public bool IsAktivTanev { get; private set; }
        public int IntezmenyId { get; set; }

        public DateTime LekerdezesNapja
        {
            get { return _lekerdezesNapja; }
            set
            {
                if (_tanevElsoNapja.HasValue && _tanevUtolsoNapja.HasValue)
                {
                    if (value >= _tanevElsoNapja.Value && value <= _tanevUtolsoNapja.Value)
                    {
                        _lekerdezesNapja = value;
                    }
                }
                else
                {/*ha nincs _TanevElsoNapja akkor nem tudjuk vizsgálni*/
                    _lekerdezesNapja = value;
                }
            }
        }

        public int? FeladatKategoriaId { get; set; }
        public int? SearchMuveszetiAgId { get; set; }
        public bool ForOktober { get; set; }
        public int? TanterviJellegSearchId { get; set; }
    }
}