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

namespace FishDice.LuckyDice
{
    public sealed class DiceRollResult
    {
        private DiceRollResult(
            string rollSessionId,
            string diceSetId,
            DiceSetType setType,
            int diceCount,
            IReadOnlyList<DiceFace> faces,
            int multiplier,
            string triggerSource)
        {
            RollSessionId = rollSessionId;
            DiceSetId = diceSetId;
            SetType = setType;
            DiceCount = diceCount;
            Faces = faces.ToArray();
            Multiplier = multiplier;
            TriggerSource = triggerSource;
        }

        public string RollSessionId { get; }

        public string DiceSetId { get; }

        public DiceSetType SetType { get; }

        public int DiceCount { get; }

        public IReadOnlyList<DiceFace> Faces { get; }

        public int Multiplier { get; }

        public string TriggerSource { get; }

        public static DiceRollResult Create(
            string rollSessionId,
            string diceSetId,
            DiceSetType setType,
            IReadOnlyList<DiceFace> faces,
            int multiplier,
            string triggerSource)
        {
            if (faces == null)
            {
                throw new ArgumentNullException(nameof(faces));
            }

            return new DiceRollResult(
                rollSessionId,
                diceSetId,
                setType,
                faces.Count,
                faces,
                multiplier,
                triggerSource);
        }

        public static DiceRollResult FromConfig(
            string rollSessionId,
            DiceSetConfig config,
            IReadOnlyList<DiceFace> faces,
            int multiplier,
            string triggerSource)
        {
            return new DiceRollResult(
                rollSessionId,
                config.DiceSetId,
                config.SetType,
                config.DiceCount,
                faces,
                multiplier,
                triggerSource);
        }
    }
}
