using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace SASDesktop.Models
{
    partial class Citizen
    {
        public string GetHumanName
        {
            get
            {
                return $"{Surname} {Name[0]}. {Patronymic[0]}.";
            }

        }

        public string NameAndBirthdate
        {
            get
            {
                return GetHumanName + DateOfBirth.ToString();
            }
        }
        public string GetHumanPass
        {
            get
            {
                return $"{PassSeries} | {PassNumber}";
            }
        }

        public ImageSource GetFace
        {
            get
            {
                if (this.File == null)
                {
                    return null;
                }
                return this.File.ImageSource;
            }
        }
    }

    partial class File
    {
        public ImageSource ImageSource
        {
            get
            {
                if (this.BinaryData == null)
                {
                    return null;
                }
                BitmapImage biImg = new BitmapImage();
                MemoryStream ms = new MemoryStream(BinaryData);
                biImg.BeginInit();
                biImg.StreamSource = ms;
                biImg.EndInit();
                ImageSource imgSrc = biImg as ImageSource;
                return imgSrc;
            }
        }
    }

    partial class Color
    {
        public string HumanName
        {
            get
            {
                return $"{NameRus} ({HEX})";
            }
        }
    }

    partial class Transport
    {
        public string ListGeneral
        {
            get
            {
                return Model1.Brand1.Name + " " + Model1.Name + " " + RelaseYear.ToString();
            }
        }

        public string CurrentOwnerText
        {
            get
            {
                if (TransportOwnerships.Count == 0)
                {
                    return "<Нет владельцев>";
                }
                
                var currentOwner = TransportOwnerships.OrderByDescending(to => to.CreatedAt).FirstOrDefault();
                return currentOwner.Citizen1.GetHumanName;
            }
        }
    }
}