<?php

namespace App\Repositories\Shop;

use App\Models\Shop\InvoicePayment;

class InvoicePayments
{
    public static function get($id, $relations = false)
    {
        return $relations ? InvoicePayment::with($relations)->findOrFail($id) : InvoicePayment::findOrFail($id);
    }

    public static function store($data)
    {
        return ($data['id'] ?? false) ? self::update($data) : self::create($data);
    }

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

    public static function update($data, $id = false)
    {
        $id = $id ? $id : $data['id'];
        $item = self::get($id);
        $item->update($data);

        return $item;
    }

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

    public static function getPaymentType($id)
    {
        return self::PaymentTypes()[$id] ?? false;
    }

    public static function PaymentTypes()
    {
        return [
            '',
            'CB',
            'CHEQUE',
            'VIREMENT',
        ];
    }
}
