<?php

namespace App\Traits;

use App\Models\Contract;
use App\Models\JobPackage;

trait GenerateCodeTrait
{
    protected function generateContractNumber(string $prefix = 'KTR', int $year = null): string
    {
        $year = $year ?? date('Y');
        $count = Contract::whereYear('created_at', $year)->count() + 1;
        return $prefix . '/' . $year . '/' . str_pad($count, 3, '0', STR_PAD_LEFT);
    }

    protected function generatePackageCode(): string
    {
        $year = date('Y');
        $count = JobPackage::whereYear('created_at', $year)->count() + 1;
        return 'PKG/' . $year . '/' . str_pad($count, 4, '0', STR_PAD_LEFT);
    }
}