<?php

namespace App\Repositories\Shop;

use App\Models\Shop\Package;

class Packages
{

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

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

    public static function getName($id)
    {
        return self::get($id)->value;
    }

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

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

    public static function create($data)
    {
        return Package::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 destroy($id)
    {
        return Package::destroy($id);
    }
}
