<?php

namespace App\Http\Controllers;

use App\Domain\Financial\Models\Payment;
use App\Domain\POS\Models\POSTransaction;
use App\Domain\POS\Models\ReceiptTemplate;
use App\Domain\POS\Services\ReceiptService;
use Illuminate\Http\Request;

class ReceiptController extends Controller
{
    public function __construct(
        private ReceiptService $receiptService,
    ) {}

    public function posPrint(POSTransaction $transaction)
    {
        $template = ReceiptTemplate::resolveFor(
            $transaction->branch_id,
            'pos'
        );

        $data = $this->receiptService->buildPosReceiptData($transaction, $template);

        return view('receipts.pos', ['data' => $data]);
    }

    public function paymentPrint(Payment $payment)
    {
        $template = ReceiptTemplate::resolveFor(
            $payment->branch_id ?? auth()->user()->branch_id,
            'pos'
        );

        $data = $this->receiptService->buildPaymentReceiptData($payment, $template);

        return view('receipts.pos', ['data' => $data]);
    }
}
