43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CzokoŚmieciarka.DataModels.Interfaces;
|
|
using CzokoŚmieciarka.DataModels.Interfaces.TrashCans;
|
|
|
|
namespace CzokoŚmieciarka.DataModels.Models.Steps
|
|
{
|
|
public class SpillStep : IStep
|
|
{
|
|
public SpillStep(IGarbageCollector garbageCollector, ADump dump, ITypeOfGarbage typeOfGarbage)
|
|
{
|
|
this._garbageCollector = garbageCollector;
|
|
this._dump = dump;
|
|
this._typeOfGarbage = typeOfGarbage;
|
|
}
|
|
|
|
private IGarbageCollector _garbageCollector;
|
|
private ADump _dump;
|
|
private ITypeOfGarbage _typeOfGarbage;
|
|
|
|
public void Invoke()
|
|
{
|
|
if(_garbageCollector.Coords != _dump.Coords)
|
|
throw new WrongPositionException("Śmieciarka nie na terenie podanego wyspiska");
|
|
|
|
if(_dump.TypeOfGarbage != _typeOfGarbage)
|
|
throw new TrashContainerNotFound($"Wysypisko nie przyjmuje smieci typu {_typeOfGarbage.GarbageType}");
|
|
|
|
if(_garbageCollector.TrashContainers.All(c => c.TypeOfGarbage != _typeOfGarbage))
|
|
throw new TrashContainerNotFound($"Smieciarka nie ma pojemnika na {_typeOfGarbage.GarbageType}!");
|
|
|
|
var garbage = _garbageCollector.TrashContainers.Where(t => t.TypeOfGarbage == _typeOfGarbage)
|
|
.Select(t => t.TakeGarbage())
|
|
.Aggregate((a, b) => a + b);
|
|
|
|
_dump.AddGarbage(garbage);
|
|
}
|
|
}
|
|
}
|