<?php

namespace App\Modules\FINANCE\Services;

use App\Modules\FINANCE\Models\Invoice;

class InvoiceNumberService
{
    /**
     * Generate a unique invoice number based on company settings (mocked for now).
     */
    public function generate($companyId, $type = 'invoice')
    {
        $prefix = $type === 'invoice' ? 'INV' : 'QT';
        $year = date('Y');
        
        $count = Invoice::where('company_id', $companyId)
            ->where('invoice_number', 'like', "{$prefix}-{$year}-%")
            ->count() + 1;

        return "{$prefix}-{$year}-" . str_pad($count, 4, '0', STR_PAD_LEFT);
    }
}
