﻿using System;
using System.Linq;
using Microsoft.EntityFrameworkCore;

namespace BrillionCore.Data.Model.Account
{
	public class FetchUserAccountByIdQuery : IQuery
	{
		public Guid UserAccountId { get; }

		public FetchUserAccountByIdQuery(Guid userAccountId)
		{
			UserAccountId = userAccountId;
		}
	}


	public class FetchUserAccountByIdQueryHandler : IQueryHandler<FetchUserAccountByIdQuery, UserAccount>
	{
		private readonly BrillionDbContext _dbContext;

		public FetchUserAccountByIdQueryHandler(BrillionDbContext dbContext)
		{
			_dbContext = dbContext;
		}

		public UserAccount Execute(FetchUserAccountByIdQuery query)
		{
			return _dbContext.UserAccounts
				.Include(ua => ua.AccountRoles)
				.SingleOrDefault(ua => ua.Id == query.UserAccountId);
		}
	}
}
