<?php

namespace App\Repositories\Shop;

use App\Models\Shop\Invoice;

class Invoices
{
    public static function getOptions()
    {
        return Invoice::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
    }

    public static function getOptionsByPackage($package_id)
    {
        return Invoice::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
    }

    public static function getAll()
    {
        return Invoice::orderBy('value', 'asc')->get();
    }

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

    public static function store($data)
    {
        $id = isset($data['id']) ? $data['id'] : false;
        $item = $id ? self::update($data, $id) : self::create($data);
        return $item->id;
    }

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

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

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