<commit_before><?php

namespace App\Http\Controllers\User;

use App\Events\NewBooking;
use App\Http\Controllers\Controller;
use App\Models\Business;
use App\Models\Service;
use App\Services\ConciergeService;
use Carbon;
use Event;
use Flash;
use Illuminate\Http\Request;
use Notifynder;

/**
 * FOR REFACTOR:
 *     - Use constructor dependency injection for Auth, Flash, Event.
 */
class AgendaController extends Controller
{
    private $concierge;

    public function __construct(ConciergeService $concierge)
    {
        $this->concierge = $concierge;
        parent::__construct();
    }

    /**
     * get Index.
     *
     * @return Response Rendered list view for User Appointments
     */
    public function getIndex()
    {
        $this->log->info(__METHOD__);

        $appointments = $this->concierge->getUnarchivedAppointmentsFor(auth()->user());

        return view('user.appointments.index', compact('appointments'));
    }

    /**
     * get Availability for Business.
     *
     * @param Business $business Business to query
     *
     * @return Response Rendered view of Appointment booking form
     */
    public function getAvailability(Business $business)
    {
        $this->log->info(__METHOD__);

        Notifynder::category('user.checkingVacancies')
           ->from('App\Models\User', auth()->user()->id)
           ->to('App\Models\Business', $business->id)
           ->url('http://localhost')
           ->send();

        if (!auth()->user()->getContactSubscribedTo($business)) {
            $this->log->info('  [ADVICE] User not subscribed to Business');

            Flash::warning(trans('user.booking.msg.you_are_not_subscribed_to_business'));

            return redirect()->back();
        }

        $includeToday = $business->pref('appointment_take_today');

        $this->concierge->setBusiness($business);

        $availability = $this->concierge->getVacancies(auth()->user(), 'today', 7);

        return view(
            'user.appointments.'.$business->strategy.'.book',
            compact('business', 'availability', 'includeToday')
        );
    }

    /**
     * post Store.
     *
     * @param Request $request Input data of booking form
     *
     * @return Response Redirect to Appointments listing
     */
    public function postStore(Request $request)
    {
        $this->log->info(__METHOD__);

        //////////////////
        // FOR REFACTOR //
        //////////////////

        $issuer = auth()->user();

        $business = Business::findOrFail($request->input('businessId'));
        $contact = $issuer->getContactSubscribedTo($business->id);
        $service = Service::find($request->input('service_id'));

        $strDateTime = $request->input('_date').' '.$business->pref('start_at');
        $datetime = Carbon::parse($strDateTime)->timezone($business->timezone);
        $comments = $request->input('comments');

        $this->concierge->setBusiness($business);

        $appointment = $this->concierge->makeReservation($issuer, $business, $contact, $service, $datetime, $comments);

        if (false === $appointment) {
            $this->log->info('[ADVICE] Unable to book');

            Flash::warning(trans('user.booking.msg.store.error'));
            return redirect()->route('user.agenda');
        }

        if (!$appointment->exists) {
            $this->log->info('[ADVICE] Appointment is duplicated');
            <commit_msg>Fix timezone reading when making a reservation<commit_after><?php

namespace App\Http\Controllers\User;

use App\Events\NewBooking;
use App\Http\Controllers\Controller;
use App\Models\Business;
use App\Models\Service;
use App\Services\ConciergeService;
use Carbon;
use Event;
use Flash;
use Illuminate\Http\Request;
use Notifynder;

/**
 * FOR REFACTOR:
 *     - Use constructor dependency injection for Auth, Flash, Event.
 */
class AgendaController extends Controller
{
    private $concierge;

    public function __construct(ConciergeService $concierge)
    {
        $this->concierge = $concierge;
        parent::__construct();
    }

    /**
     * get Index.
     *
     * @return Response Rendered list view for User Appointments
     */
    public function getIndex()
    {
        $this->log->info(__METHOD__);

        $appointments = $this->concierge->getUnarchivedAppointmentsFor(auth()->user());

        return view('user.appointments.index', compact('appointments'));
    }

    /**
     * get Availability for Business.
     *
     * @param Business $business Business to query
     *
     * @return Response Rendered view of Appointment booking form
     */
    public function getAvailability(Business $business)
    {
        $this->log->info(__METHOD__);

        Notifynder::category('user.checkingVacancies')
           ->from('App\Models\User', auth()->user()->id)
           ->to('App\Models\Business', $business->id)
           ->url('http://localhost')
           ->send();

        if (!auth()->user()->getContactSubscribedTo($business)) {
            $this->log->info('  [ADVICE] User not subscribed to Business');

            Flash::warning(trans('user.booking.msg.you_are_not_subscribed_to_business'));

            return redirect()->back();
        }

        $includeToday = $business->pref('appointment_take_today');

        $this->concierge->setBusiness($business);

        $availability = $this->concierge->getVacancies(auth()->user(), 'today', 7);

        return view(
            'user.appointments.'.$business->strategy.'.book',
            compact('business', 'availability', 'includeToday')
        );
    }

    /**
     * post Store.
     *
     * @param Request $request Input data of booking form
     *
     * @return Response Redirect to Appointments listing
     */
    public function postStore(Request $request)
    {
        $this->log->info(__METHOD__);

        //////////////////
        // FOR REFACTOR //
        //////////////////

        $issuer = auth()->user();

        $business = Business::findOrFail($request->input('businessId'));
        $contact = $issuer->getContactSubscribedTo($business->id);
        $service = Service::find($request->input('service_id'));

        $strDateTime = $request->input('_date').' '.$business->pref('start_at');
        $datetime = Carbon::parse($strDateTime.' '.$business->timezone)->setTimezone('UTC');

        $comments = $request->input('comments');

        $this->concierge->setBusiness($business);

        $appointment = $this->concierge->makeReservation($issuer, $business, $contact, $service, $datetime, $comments);

        if (false === $appointment) {
            $this->log->info('[ADVICE] Unable to book');

            Flash::warning(trans('user.booking.msg.store.error'));
            return redirect()->route('user.agenda');
        }

        if (!$appointment->exists) {
            $this->log->info('[ADVICE] Appointment is duplicated');
            
{'fraction_non_alphanumeric': 0.16128565223686114, 'fraction_numerical': 0.0002895613146083683, 'mean_word_length': 2.5885714285714285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, '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': '2971015', 'n_tokens_mistral': 1975, 'n_tokens_neox': 1914, 'n_words': 371}