﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectSoccerPlayer
{
    internal class SoccerPlayer
    {
        private int _playerId;

        #region OldProperties
        public int PlayerId
        {
            get
            {
                return _playerId;
            }
        }

        public string FirstName { get; set; } = string.Empty;
        public string LastName { get; set; } = string.Empty;

        public DateTime? BirthDate { get; set; }
        public float? Height { get; set; }
        public float? Weight { get; set; }
        public bool? IsAvailable { get; set; }
        public SoccerPosition Position { get; set; } = SoccerPosition.Unknown;
        #endregion

        public DateTime? ContractUntil { get; set; }
        public int? ShirtNumber { get; set; }
        public bool? IsInjured { get; set; }
        public int? MatchesPlayed { get; set; }
        public int? GoalsScored { get; set; }


        public SoccerPlayer(int playerId)
        {
            if (playerId < 0)
                throw new ArgumentException("PlayerId must be greater than zero!");

            this._playerId = playerId;
            //FirstName = string.Empty;
        }

        public int GetAge()
        {
            if (BirthDate == null)
                throw new InvalidOperationException("Birthday must be set before calculating!");

            var bd = BirthDate.Value;
            int age = DateTime.Today.Year - bd.Year;

            if (DateTime.Today < bd.AddYears(age))
                age--;

            return age;
        }


        public void PrintClubInfo()
        {
            if (string.IsNullOrWhiteSpace(FirstName) || string.IsNullOrWhiteSpace(LastName))
                throw new InvalidOperationException("Cannot Merge without Name Infos!");

            string contract = ContractUntil?.ToShortDateString() ?? "n/a"; // ? if(ContractUntil == null)
            //string injured = IsInjured ? "Yes" : "No";  //Iif wie in VBA!
            string injured = IsInjured switch
            {
                true => "Yes",
                false => "No",
                null => "unknown"
            };

            Console.WriteLine("------------- Club Info ---------------");
            Console.WriteLine("Name: " + FirstName + " " + LastName); // & 
            Console.WriteLine("Shirt Number: {0}", ShirtNumber.ToString());
            Console.WriteLine($"Contract Until: {contract}");
            Console.WriteLine($"Injured: {injured}");
            Console.WriteLine($"Matches Played: {MatchesPlayed.ToString()}");
            Console.WriteLine($"Goals Scored: {GoalsScored.ToString()}");
            Console.WriteLine("-----------------------------------------");
        }

        public void PrintInfo()
        {
            if (string.IsNullOrWhiteSpace(FirstName) || string.IsNullOrWhiteSpace(LastName))
                throw new InvalidOperationException("Cannot Merge without Name Infos!");

            string position = Position.ToString();
            string birthday = BirthDate?.ToShortDateString() ?? "n/a";
            string age = BirthDate != null ? GetAge().ToString() : "n/a";

            Console.WriteLine("---------ID: " + PlayerId.ToString() + "---------");
            Console.WriteLine("Player Info:");
            Console.WriteLine("Name: " + FirstName + " " + LastName);
            Console.WriteLine("Birthday: " + BirthDate.ToString());
            Console.WriteLine("Age: " + age);
            Console.WriteLine("Position: " + position);
            Console.WriteLine("-----------------");
        }


        public void Merge()
        {

            if (string.IsNullOrWhiteSpace(FirstName) || string.IsNullOrWhiteSpace(LastName))
                throw new InvalidOperationException("Cannot Merge without Name Infos!");


        }
    }
}
