using System;
using System.Collections.Generic;
using System.Linq;
using Assets.AnnotationPass;
using Assets.Common;
using Assets.GridGenerator;

namespace Assets
{
    class MapGenerator
    {
        private IGridGenerator _gridGenerator;
        private ICollection<IAnnotationPass> _annotationPasses = new List<IAnnotationPass>();
        private Map _result;

        public IEnumerable<IAnnotationPass> AnnotationPasses => _annotationPasses.AsEnumerable();
        public IGridGenerator GridGenerator => _gridGenerator;
        public Map Result => _result;
        public bool IsDone => _result != null;

        public MapGenerator(IGridGenerator gridGenerator)
        {
            _gridGenerator = gridGenerator;
        }

        public void AddAnnotationPass(IAnnotationPass pass)
        {
            _annotationPasses.Add(pass);
        }

        public Map Generate(double width, double height)
        {
            if (_result != null)
                return _result;

            _result = _gridGenerator.CreateGrid(width, height);
            foreach (var pass in _annotationPasses)
                pass.Annotate(_result);

            return _result;
        }
    }
}