<?php

namespace App\Repositories\Shop;

use App\Models\Shop\Homepage;

class Homepages
{

    public static function getLast()
    {
        $model = Homepage::latest('id')->first();
        return $model ? $model->text : '';
    }

    public static function getHomepage()
    {
        return self::get(1)->text ?? '';
    }

    public static function getFooter()
    {
        return self::get(2)->text  ?? '';
    }

    public static function getExtraFooter()
    {
        return self::get(3)->text  ?? '';
    }

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

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

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