<?php

namespace App\Commands\Transmittal;

use App\Commands\Command;
use App\Models\Transmittal;
use Illuminate\Database\Eloquent\Model;

class GenerateTransmittalSeries implements Command
{

    public function execute(array $data): string
    {
        $lastSeries = Transmittal::query()->orderBy('id', 'desc')->first();

        if ($lastSeries) {
            $series = explode('-', $lastSeries->series)[1];
            return  'TR-'.str_pad((int)$series + 1, 10, '0', STR_PAD_LEFT);
        }

        return $series = 'TR-'.str_pad(1, 10, '0', STR_PAD_LEFT);
    }
}
