<?php


namespace App\Repositories;


use App\Payment;
use App\PaymentType;
use Carbon\Carbon;
use Illuminate\Support\Facades\DB;

class PaymentRepository implements RepositoryInterface
{
    public static function all() {
        return Payment::all();
    }

    public static function create(array $data) {
        return Payment::create($data);
    }

    public static function update(array $data, $id) {
        Payment::findOrFail($id)->update($data);
        return Payment::find($id);
    }

    public static function delete($id){
        return Payment::destroy($id);
    }

    public static function find($id){
        return Payment::find($id);
    }

    public static function paymentType($id) {
        return Payment::findOrFail($id)->paymentType;
    }

    public static function box($id)
    {
        return Payment::findOrFail($id)->box;
    }

    public static function user($id) {
        return Payment::findOrFail($id)->user;
    }

    public static function pay($id, $payment_type_id)
    {
        return PaymentRepository::update([
            "payment_type_id" => $payment_type_id,
            "charged" => true
        ], $id);
    }

}
