using System.Collections.Generic;
using System.Linq;

namespace Nox.Game {
    public class PartyCreatorModel {
        private readonly ICharacterFactory characterFactory;
        private readonly IPartyFactory partyFactory;
        private readonly List<CharacterCreationRequest> characterCreationRequests;
        private readonly PartySettings partySettings;

        public PartyCreatorModel(ICharacterFactory characterFactory,
            IPartyFactory partyFactory,
            List<CharacterCreationRequest> characterCreationRequests,
            PartySettings partySettings) {
            this.characterFactory = characterFactory;
            this.partyFactory = partyFactory;
            this.characterCreationRequests = characterCreationRequests;
            this.partySettings = partySettings;
        }
        public PartyDefinition CreatePartyForNewRun() {
            if(characterCreationRequests.Count > partySettings.maxPartySize) {
                throw new System.ArgumentException("Too many characters requested.");
            }
            var protagonist = characterFactory.CreateProtagonist(characterCreationRequests.Find(r => r.Role == CharacterRole.Protagonist));
            return partyFactory.Create(protagonist);
        }
    }
}
