<?php

namespace App\Modules\Procurement\Services;

use App\Modules\Procurement\Models\GoodsReceipt;
use App\Modules\Procurement\Support\GoodsReceiptLifecycleStatus;
use App\Support\SystemReferenceAssigner;
use App\Support\SystemReferenceGenerator;

final class GoodsReceiptDraftService
{
    public function __construct(
        private readonly SystemReferenceAssigner $references,
    ) {}

    public function createDraft(int $tenantId, int $purchaseOrderId, int $warehouseId): GoodsReceipt
    {
        $receipt = GoodsReceipt::withoutGlobalScopes()->create([
            'tenant_id' => $tenantId,
            'purchase_order_id' => $purchaseOrderId,
            'warehouse_id' => $warehouseId,
            'status' => GoodsReceiptLifecycleStatus::Draft->value,
        ]);

        return $this->references->assign($receipt, SystemReferenceGenerator::GOODS_RECEIPT, 'receipt_number');
    }
}
