From 4b23c305089bc3066c0bcd5d67fc0ccd14a79868 Mon Sep 17 00:00:00 2001 From: Ksi Date: Mon, 20 May 2024 23:19:19 +0200 Subject: [PATCH] Add MaturingItemManager.cs --- src/Core/ProposedCode/MaturingItemManager.cs | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Core/ProposedCode/MaturingItemManager.cs diff --git a/src/Core/ProposedCode/MaturingItemManager.cs b/src/Core/ProposedCode/MaturingItemManager.cs new file mode 100644 index 0000000..1b63218 --- /dev/null +++ b/src/Core/ProposedCode/MaturingItemManager.cs @@ -0,0 +1,39 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) KsiProgramming. All rights reserved. +// +//----------------------------------------------------------------------- + +namespace GildedRoseKata.ProposedCode +{ + using GildedRoseKata.OriginalCode; + + public class MaturingItemManager + { + private readonly IDictionary strategies; + + public MaturingItemManager(IDictionary strategies) + { + this.strategies = strategies; + } + + public Item MatureItem(Item item) + { + if (this.strategies.TryGetValue(item.Name, out var strategy)) + { + var request = new ItemMaturingRequest(new Quality(item.Quality), new SellIn(item.SellIn)); + var response = strategy.Update(request); + + return new () + { + Name = item.Name, + Quality = response.quality.value, + SellIn = response.sellIn.value, + }; + } + + // Handle case where item type doesn't have a strategy + return item; + } + } +}