<?php

namespace Modules\Payment\Repositories;

use Illuminate\Database\Eloquent\Collection;
use Modules\Payment\Models\Order;
use Modules\Payment\Repositories\Interfaces\OrderRepositoryInterface;

class OrderRepository implements OrderRepositoryInterface
{
    public function __construct(
        private Order $model
    ) {}

    public function all(): Collection
    {
        return $this->model->all();
    }

    public function find(int $id): ?Order
    {
        return $this->model->find($id);
    }

    public function findByOrderNumber(string $orderNumber): ?Order
    {
        return $this->model->where('order_number', $orderNumber)->first();
    }

    public function create(array $data): Order
    {
        return $this->model->create($data);
    }

    public function updateStatus(int $id, string $status): Order
    {
        $order = $this->find($id);
        $order->update(['status' => $status]);
        return $order->fresh();
    }

    public function updatePaymentStatus(int $id, string $status): Order
    {
        $order = $this->find($id);
        $order->update(['payment_status' => $status]);
        return $order->fresh();
    }
}
