using SewerStammGen.Shared.Contracts;
using SewerStammGen.Shared.Domain;
using StammGenerator.Commands;
using StammGenerator.Interface;
using StammGenerator.ViewModel;
using System.Threading.Tasks;

namespace StammGenerator.Commands
{
    internal class HaltungEditSaveCommand : AsyncCommandBase
    {
        private readonly IHaltungDataService _haltungDataService;
        private readonly IRenavigator _renavigator;
        private readonly Kanal _model;

        public HaltungEditSaveCommand(IHaltungDataService haltungDataService,IRenavigator renavigator,HaltungEditViewModel haltungEditViewModel)
        {
            
            this._haltungDataService = haltungDataService;
            this._renavigator = renavigator;
            this._model = haltungEditViewModel.Model;
        }

        public override async Task ExecuteAsync(object? parameter)
        {
            if(_model.Id == -1) // Neu anlegen
            {
                await _haltungDataService.Create(_model);
            }
            else
            {
                await _haltungDataService.Update(_model);
            }

            _renavigator.Renavigate();
        }
    }
}
