<?php

namespace Modules\Banner\Repositories;

use Modules\Banner\Interfaces\BannerRepositoryInterface;
use Modules\Banner\Models\Banner;
use Modules\Banner\Models\BannerDescription;
use Modules\Banner\Models\BannerPhoto;

class BannerRepository implements BannerRepositoryInterface
{
    public function get(array $request)
    {
        $builder = Banner::with(['type','category','photos']);
        return $builder;
    }

    public function getItem(int $id)
    {
        return Banner::with(['type','category','photos'])->find($id);
    }

    public function getItemByCategoryID(int $category_id)
    {
        return Banner::where('category_id',$category_id)->firstOrFail();
    }

    public function checkItem(int $id)
    {
        return Banner::with(['photos'])->findOrFail($id);
    }

    public function getItemTrashed(int $id)
    {
        $banner = Banner::onlyTrashed()->find($id);
        return $banner ;
    }

    public function create(array $request): Banner
    {
        $banner = Banner::create($request);
        return $banner;
    }

    public function update(array $request, ?Banner $banner): Banner
    {
        $banner->update($request);

        return $banner;
    }


    public function photos($banner_id)
    {
        return BannerPhoto::where('banner_id',$banner_id)->get();
    }

    public function deletePhotos(int $id)
    {
        BannerPhoto::where('banner_id',$id)->delete();
    }

    public function createPhotos($request)
    {
        BannerPhoto::create($request);
    }
}
