﻿using System.Collections.Generic;
using System.Linq;
using Blockchain.Interfaces;

namespace PaymentSystem
{
    public class PaymentSystemBlock : IBlock
    {
        public long Index { get; set; }

        public string Creator { get; set; }

        public IList<ITransaction> Transactions { get; } = new List<ITransaction>();


        public string GetHash()
        {
            return (
                Index + 
                Creator +
                Transactions
                    .Select(transaction => transaction.GetHash())
                    .Aggregate((result, transactionHash) => result + transactionHash)
                    .GetSHA512Hash()
                )
                .GetSHA512Hash();
        }
    }
}
