package com.gildedrose;

class GildedRose {
	private static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
	private static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
	private static final String AGED_BRIE = "Aged Brie";
	Item[] items;

	public GildedRose(Item[] items) {
		this.items = items;
	}

	public void updateQuality() {
		for (int i = 0; i < items.length; i++) {

			Item item = items[i];
			if (!item.name.equals(AGED_BRIE) && !item.name.equals(BACKSTAGE_PASSES)) {
				if (item.quality > 0) {
					if (!item.name.equals(SULFURAS)) {
						item.quality = item.quality - 1;
					}
				}
			} else {
				if (item.quality < 50) {
					item.quality = item.quality + 1;

					if (item.name.equals(BACKSTAGE_PASSES)) {
						if (item.sellIn < 11) {
							if (item.quality < 50) {
								item.quality = item.quality + 1;
							}
						}

						if (item.sellIn < 6) {
							if (item.quality < 50) {
								item.quality = item.quality + 1;
							}
						}
					}
				}
			}

			decrementSellIn(item);

			if (item.sellIn < 0) {
				if (item.name.equals(AGED_BRIE)) {
					if (item.quality < 50) {
						item.quality = item.quality + 1;
					}
				} else {
					if (!item.name.equals(BACKSTAGE_PASSES)) {
						if (item.quality > 0) {
							if (!item.name.equals(SULFURAS)) {
								item.quality = item.quality - 1;
							}
						}
					} else {
						item.quality = 0;
					}
				}
			}
		}

	}

	public void decrementSellIn(Item item) {
		if (!item.name.equals(SULFURAS)) {
			item.sellIn = item.sellIn - 1;
		}
	}
}

@@ -1192,25 +1192,17 @@
 %09%09%09%7D
- else %7B%0A%09
+%0A
 %09%09%09%09if (
 !ite
@@ -1189,33 +1189,32 @@
 %7D%0A%09%09%09%09%7D%0A%09%09%09%09if (
-!
 item.name.equals
@@ -1236,29 +1236,24 @@
 ES)) %7B%0A%09%09%09%09%09
-%09if (
 item.quality
@@ -1253,26 +1253,27 @@
 quality 
-%3E 0) %7B
+= 0;
 %0A%09%09%09
+%09%7D%0A
 %09%09%09%09if (
@@ -1294,44 +1294,107 @@
 als(
-SULFURAS)) %7B%0A%09%09
+AGED_BRIE) && !item.name.equals(BACKSTAGE_PASSES)%0A
 %09%09%09%09%09%09
+&& !
 item.
-quality = 
+name.equals(SULFURAS)) %7B%0A%09%09%09%09%09if (
 item
@@ -1406,50 +1406,36 @@
 ity 
-- 1;
+%3E 0) %7B
 %0A%09%09%09%09%09%09
-%09%7D%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D else %7B%0A%09%09%09%09%09%09
+item.quality = 
 item
@@ -1439,27 +1439,27 @@
 tem.quality 
-= 0
+- 1
 ;%0A%09%09%09%09%09%7D%0A%09%09%09

refactor 2nd part