<commit_before>﻿namespace RightpointLabs.Pourcast.Application.Orchestrators.Concrete
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using RightpointLabs.Pourcast.Application.Orchestrators.Abstract;
    using RightpointLabs.Pourcast.Application.Payloads;
    using RightpointLabs.Pourcast.Application.Transactions;
    using RightpointLabs.Pourcast.Domain.Models;
    using RightpointLabs.Pourcast.Domain.Repositories;

    public class BeerOrchestrator : BaseOrchestrator, IBeerOrchestrator
    {
        private readonly IBeerRepository _beerRepository;
        private readonly IBreweryRepository _breweryRepository;

        private readonly ITapRepository _tapRepository;

        private readonly IKegRepository _kegRepository;

        public BeerOrchestrator(IBeerRepository beerRepository, IBreweryRepository breweryRepository, ITapRepository tapRepository, IKegRepository kegRepository)
        {
            if (beerRepository == null) throw new ArgumentNullException("beerRepository");
            if(breweryRepository == null) throw new ArgumentNullException("breweryRepository");
            if (tapRepository == null) throw new ArgumentNullException("tapRepository");
            if (kegRepository == null) throw new ArgumentNullException("kegRepository");

            _beerRepository = beerRepository;
            _breweryRepository = breweryRepository;
            _tapRepository = tapRepository;
            _kegRepository = kegRepository;
        }

        public IEnumerable<Beer> GetBeers()
        {
            return _beerRepository.GetAll();
        }

        public IEnumerable<BeerOnTap> GetBeersOnTap()
        {
            var taps = _tapRepository.GetAll();

            return taps.Select(tap => CreateBeerOnTap(tap));
        }

        public BeerOnTap GetBeerOnTap(string tapId)
        {
            var tap = _tapRepository.GetById(tapId);

            return CreateBeerOnTap(tap);
        }

        private BeerOnTap CreateBeerOnTap(Tap tap)
        {
            if (tap.HasKeg)
            {
                var keg = _kegRepository.GetById(tap.KegId);
                var beer = _beerRepository.GetById(keg.BeerId);
                var brewery = _breweryRepository.GetById(beer.BreweryId);

                return new BeerOnTap() { Tap = tap, Keg = keg, Beer = beer, Brewery = brewery };
            }
            else
            {
                return new BeerOnTap() { Tap = tap };
            }
        }

        public IEnumerable<Beer> GetByName(string name)
        {
            return _beerRepository.GetAllByName(name);
        }

        public IEnumerable<Beer> GetByBrewery(string breweryId)
        {
            return _beerRepository.GetByBreweryId(breweryId);
        }

        public Beer GetById(string id)
        {
            return _beerRepository.GetById(id);
        }

        [Transactional]
        public string CreateBeer(string name, double abv, double baScore, string style, string color, string glass, string breweryId)
        {
            var id = string.Empty;

            id = _beerRepository.NextIdentity();
            var beer = new Beer(id, name)
            {
                ABV = abv,
                BAScore = baScore,
                BreweryId = breweryId,
                Color = color,
                Glass = glass,
                Style = style,
                RPScore = 0
            };
            _beerRepository.Add(beer);

            return id;
        }

        public IEnumerable<Beer> GetBeersByName(string name)
        {
            return _beerRepository.GetAllByName(name);
        }
<commit_msg>Fix beer orch issue<commit_after>﻿namespace RightpointLabs.Pourcast.Application.Orchestrators.Concrete
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    using RightpointLabs.Pourcast.Application.Orchestrators.Abstract;
    using RightpointLabs.Pourcast.Application.Payloads;
    using RightpointLabs.Pourcast.Application.Transactions;
    using RightpointLabs.Pourcast.Domain.Models;
    using RightpointLabs.Pourcast.Domain.Repositories;

    public class BeerOrchestrator : BaseOrchestrator, IBeerOrchestrator
    {
        private readonly IBeerRepository _beerRepository;
        private readonly IBreweryRepository _breweryRepository;

        private readonly ITapRepository _tapRepository;

        private readonly IKegRepository _kegRepository;

        public BeerOrchestrator(IBeerRepository beerRepository, IBreweryRepository breweryRepository, ITapRepository tapRepository, IKegRepository kegRepository)
        {
            if (beerRepository == null) throw new ArgumentNullException("beerRepository");
            if(breweryRepository == null) throw new ArgumentNullException("breweryRepository");
            if (tapRepository == null) throw new ArgumentNullException("tapRepository");
            if (kegRepository == null) throw new ArgumentNullException("kegRepository");

            _beerRepository = beerRepository;
            _breweryRepository = breweryRepository;
            _tapRepository = tapRepository;
            _kegRepository = kegRepository;
        }

        public IEnumerable<Beer> GetBeers()
        {
            return _beerRepository.GetAll();
        }

        public IEnumerable<BeerOnTap> GetBeersOnTap()
        {
            var taps = _tapRepository.GetAll();

            return taps.Select(tap => CreateBeerOnTap(tap));
        }

        public BeerOnTap GetBeerOnTap(string tapId)
        {
            var tap = _tapRepository.GetById(tapId);

            return CreateBeerOnTap(tap);
        }

        private BeerOnTap CreateBeerOnTap(Tap tap)
        {
            if (tap.HasKeg)
            {
                var keg = _kegRepository.GetById(tap.KegId);
                var beer = _beerRepository.GetById(keg.BeerId);
                var brewery = _breweryRepository.GetById(beer.BreweryId);

                return new BeerOnTap() { Tap = tap, Keg = keg, Beer = beer, Brewery = brewery };
            }
            else
            {
                return new BeerOnTap() { Tap = tap };
            }
        }

        public IEnumerable<Beer> GetByName(string name)
        {
            return _beerRepository.GetAllByName(name);
        }

        public IEnumerable<Beer> GetByBrewery(string breweryId)
        {
            return _beerRepository.GetByBreweryId(breweryId);
        }

        public Beer GetById(string id)
        {
            return _beerRepository.GetById(id);
        }

        [Transactional]
        public string CreateBeer(string name, double abv, double baScore, string style, string color, string glass, string breweryId)
        {
            var id = string.Empty;

            id = _beerRepository.NextIdentity();
            var beer = new Beer(id, name)
            {
                ABV = abv,
                BAScore = baScore,
                BreweryId = breweryId,
                RPScore = 0
            };
            _beerRepository.Add(beer);

            return id;
        }

        public IEnumerable<Beer> GetBeersByName(string name)
        {
            return _beerRepository.GetAllByName(name);
        }

{'fraction_non_alphanumeric': 0.07264661028698184, 'fraction_numerical': 0.0002772771384999307, 'mean_word_length': 2.0815890645023494, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3875585', 'n_tokens_mistral': 2030, 'n_tokens_neox': 1911, 'n_words': 401}