<?php

namespace App\Repositories;

use App\Models\IllustrationImage;
use App\Repositories\Interfaces\IllustrationImageInterface;

class IllustrationImageRepository implements IllustrationImageInterface
{
    public function getByIllustrationId($illustrationId)
    {
        return IllustrationImage::where('illustration_id', $illustrationId)->get();
    }

    public function store($illustrationId, $imageFileName)
    {
        return IllustrationImage::create([
            'illustration_id' => $illustrationId,
            'image' => $imageFileName
        ]);
    }

    public function delete($id)
    {
        $image = IllustrationImage::find($id);
        if ($image) {
            $image->delete();
            return true;
        }
        return false;
    }

    public function deleteByIllustrationId($illustrationId)
    {
        $images = IllustrationImage::where('illustration_id', $illustrationId)->get();
        foreach ($images as $image) {
            $this->delete($image->id);
        }
        return true;
    }
}
