using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace factoryMethod.Gof
{
    class Program
    {
        static void Main(string[] args)
        {
            Creator usineIPhone= new ConcreteCreatorIphone();
            PhoneProduct oneIphone = usineIPhone.CreateFactoryMethod();
            Console.WriteLine(oneIphone);
            Creator usineGalaxy = new ConcreteCreatorSamsumgGalaxy();
            IEnumerable<PhoneProduct> productionBatchList = usineGalaxy.LaunchProduction(10);
            foreach (var phone in productionBatchList)
            {
                Console.WriteLine(phone);
            }
            Console.ReadKey();
        }
    }




 
    /// <summary>
    /// The 'Product' abstract class
    /// </summary>
    abstract class PhoneProduct
    {
        public Guid SerialCode { get; set; }
        public override string ToString()
        {
            return SerialCode.ToString();
        }
    }

    /// <summary>
    /// A 'ConcreteProduct' class
    /// </summary>
    class ConcreteIPhone : PhoneProduct
    {
        public override string ToString()
        {   
            return "Iphone "+base.ToString();
        }
    }

    /// <summary>
    /// A 'ConcreteProduct' class
    /// </summary>
    class ConcreteSamsumgGalaxy : PhoneProduct
    {
         public override string ToString()
        {
            return "Samsung "+base.ToString();
        }
    }

    /// <summary>
    /// The 'Creator' abstract class
    /// </summary>
    abstract class Creator
    {
        public abstract PhoneProduct CreateFactoryMethod();

        public IEnumerable<PhoneProduct> LaunchProduction(uint item)
        {
            var list = new List<PhoneProduct>();
            for (uint i = 0; i < item; i++)
            {
                list.Add(CreateFactoryMethod());
            }
            return list;
        }
    }

    /// <summary>
    /// A 'ConcreteCreator' class
    /// </summary>
    class ConcreteCreatorIphone : Creator
    {
        public override PhoneProduct CreateFactoryMethod()
        {
            PhoneProduct phone = new ConcreteIPhone();
            phone.SerialCode = Guid.NewGuid(); // can be placed into PhoneProduct ctor
            return phone;
        }
    }

    /// <summary>
    /// A 'ConcreteCreator' class
    /// </summary>
    class ConcreteCreatorSamsumgGalaxy : Creator
    {
        public override PhoneProduct CreateFactoryMethod()
        {
            PhoneProduct phone = new ConcreteSamsumgGalaxy();
            phone.SerialCode = Guid.NewGuid();// can be placed into PhoneProduct ctor
            return phone;
        }
    }
}
