<commit_before><?php

namespace FireflyIII\Shared\Toolkit;

use Carbon\Carbon;
use FireflyIII\Exception\FireflyException;
use Illuminate\Support\Collection;

/**
 * Class Reminders
 *
 * @package FireflyIII\Shared\Toolkit
 */
class Reminders
{

    /**
     * @param \Reminder $reminder
     *
     * @return int
     * @throws FireflyException
     */
    public function amountForReminder(\Reminder $reminder) {

        /** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
        $dateKit = \App::make('FireflyIII\Shared\Toolkit\Date');

        switch(get_class($reminder->remindersable)) {

            case 'Piggybank':
                $start     = new Carbon;
                $end       = !is_null($reminder->remindersable->targetdate) ? clone $reminder->remindersable->targetdate : new Carbon;
                $reminders = 0;
                while ($start <= $end) {
                    $reminders++;
                    $start = $dateKit->addPeriod($start, $reminder->remindersable->reminder, $reminder->remindersable->reminder_skip);
                }
                /*
                 * Now find amount yet to save.
                 */
                $repetition = $reminder->remindersable->currentRelevantRep();
                $leftToSave = floatval($reminder->remindersable->targetamount) - floatval($repetition->currentamount);
                $reminders = $reminders == 0 ? 1 : $reminders;
                return $leftToSave / $reminders;
                break;
            default:
                throw new FireflyException('Cannot handle class '. get_class($reminder->remindersable).' in amountForReminder.');
                break;
        }



        return 50;
    }

    /**
     *
     */
    public function getReminders()
    {
        $reminders = \Auth::user()->reminders()->get();
        return $reminders;
        //        $reminders = \Auth::user()->reminders()->where('active', true)->get();
        //        $return    = [];
        //        /** @var \Reminder $reminder */
        //        foreach ($reminders as $reminder) {
        //            $set = ['id' => $reminder->id];
        //            switch ($reminder->data->type) {
        //                case 'Test':
        //                case 'Piggybank':
        //                    $set['title'] = $reminder->title;
        //                    $set['icon']  = $reminder->data->icon;
        //                    $set['text']  = mf(floatval($reminder->data->amount));
        //                    break;
        //
        //            }
        //            $return[] = $set;
        //        }
        //
        //        return $return;
    }

    public function updateReminders()
    {

        /*
         * Reminder capable objects are (so far) only piggy banks.
         */
        /** @var \FireflyIII\Database\Piggybank $repository */
        $repository = \App::make('FireflyIII\Database\Piggybank');

        /** @var \FireflyIII\Shared\Toolkit\Date $dateKit */<commit_msg>Expanded the selection of reminders.<commit_after><?php

namespace FireflyIII\Shared\Toolkit;

use Carbon\Carbon;
use FireflyIII\Exception\FireflyException;
use Illuminate\Support\Collection;

/**
 * Class Reminders
 *
 * @package FireflyIII\Shared\Toolkit
 */
class Reminders
{

    /**
     * @param \Reminder $reminder
     *
     * @return int
     * @throws FireflyException
     */
    public function amountForReminder(\Reminder $reminder)
    {

        /** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
        $dateKit = \App::make('FireflyIII\Shared\Toolkit\Date');

        switch (get_class($reminder->remindersable)) {

            case 'Piggybank':
                $start     = new Carbon;
                $end       = !is_null($reminder->remindersable->targetdate) ? clone $reminder->remindersable->targetdate : new Carbon;
                $reminders = 0;
                while ($start <= $end) {
                    $reminders++;
                    $start = $dateKit->addPeriod($start, $reminder->remindersable->reminder, $reminder->remindersable->reminder_skip);
                }
                /*
                 * Now find amount yet to save.
                 */
                $repetition = $reminder->remindersable->currentRelevantRep();
                $leftToSave = floatval($reminder->remindersable->targetamount) - floatval($repetition->currentamount);
                $reminders  = $reminders == 0 ? 1 : $reminders;

                return $leftToSave / $reminders;
                break;
            default:
                throw new FireflyException('Cannot handle class ' . get_class($reminder->remindersable) . ' in amountForReminder.');
                break;
        }


        return 50;
    }

    /**
     *
     */
    public function getReminders()
    {
        $reminders = \Auth::user()->reminders()
                          ->where('active', 1)
                          ->where('startdate', '<=', Carbon::now()->format('Y-m-d'))
                          ->where('enddate', '>=', Carbon::now()->format('Y-m-d'))
                          ->get();

        return $reminders;
        //        $reminders = \Auth::user()->reminders()->where('active', true)->get();
        //        $return    = [];
        //        /** @var \Reminder $reminder */
        //        foreach ($reminders as $reminder) {
        //            $set = ['id' => $reminder->id];
        //            switch ($reminder->data->type) {
        //                case 'Test':
        //                case 'Piggybank':
        //                    $set['title'] = $reminder->title;
        //                    $set['icon']  = $reminder->data->icon;
        //                    $set['text']  = mf(floatval($reminder->data->amount));
        //                    break;
        //
        //            }
        //            $return[] = $set;
        //        }
        //
        //        return $return;
    }

    public function updateReminders()
    {

        /*
         * Reminder capable objects are (so far) only piggy banks.
         */
        /** @var \FireflyIII\Database\Piggybank $repository */
        $repository = \App::make('FireflyIII\Database\Piggybank');

        /** @var \FireflyIII\Shared\Toolkit\Date $dateKit */
{'fraction_non_alphanumeric': 0.14556458034718905, 'fraction_numerical': 0.0017518713170887085, 'mean_word_length': 1.4666142969363707, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 69, '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': '5209030', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1779, 'n_words': 298}