using HorseViewer.Models;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace HorseViewer
{
    public class HorseGridViewItem
    {
        public ulong Id { get; set; }
        public string Name { get; set; }
        public string Breed { get; set; }
        public string Gender { get; set; }
        public int Age { get; set; }
        public DateTime LastDrawnDate { get; set; }
        public bool IsAllDataLoaded { get; set; }
    }
    public partial class Form1 : Form
    {
        string horsePath = "";
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FileDialog fileDialog = new OpenFileDialog();
            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                horsePath = fileDialog.FileName;
            }
            var json = File.ReadAllText(horsePath);
            HorseFactory.Horses = JsonSerializer.Deserialize<Dictionary<ulong, HorseViewer.Models.Horse>>(json);

            var result = HorseFactory.GetAllHorses().Values.Select(horse => new HorseGridViewItem
            {
                Id = horse.Id ?? 0,
                Name = horse.HorseName,
                Breed = horse.Breed,
                Gender = horse.Gender,
                Age = horse.Age ?? 0,
                LastDrawnDate = horse.LastDrawnDate,
                IsAllDataLoaded = horse.IsAllDataLoaded()
            }).ToList();

            dataGridView1.DataSource = result;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
