using AutoCat.Utils;
using AutoCatCore.Model;
using AutoCatCore.MVVM;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;

namespace AutoCatCore.ViewModel
{
	public class SearchViewModel
	{
		private IDialogService dialogService;

		public ObservableCollection<Vehicle> Vehicles { get; private set; }

		public SearchViewModel(IDialogService dialogService)
		{
			this.dialogService = dialogService;
			Vehicles = new ObservableCollection<Vehicle>();
			Init();
		}

		private async void Init()
		{
			try
			{
				var result = await Api.GetVehicles();
				Vehicles.Clear();
				foreach(var vehicle in result.Items)
				{
					Vehicles.Add(vehicle);
				}
			}
			catch (Exception ex)
			{
				await dialogService.ShowErrorDialogAsync(ex.Message, "Error");
			}
		}
	}
}
