<?php

namespace App\Schedule;

use App\Models\ExportMap;
use App\Models\Report;
use Carbon\Carbon;

class BiWeekly
{
    /**
     * When is going to be the next time of invoking the report
     *
     * @param Carbon $from
     * @param Report|ExportMap $report
     * @return Carbon
     */
    public function nextTime(Carbon $from, Report|ExportMap $report)
    {
        if ($report->export_time) {
            $from->setTimeFromTimeString($report->export_time);
        }
        $from->addWeeks(2);

        if ($report->export_day_of_week) {
            $from->weekday($report->export_day_of_week);
        }

        return $from;
    }
}
