<?php

namespace App\Repositories;

use App\Models\CreativeArtImage;
use App\Repositories\Interfaces\ArtImageInterface;

class ArtImageRepository implements ArtImageInterface
{
    public function getByArtId($artId)
    {
        return CreativeArtImage::where('art_id', $artId)->get();
    }

    public function store($artId, $imageFileName)
    {
        return CreativeArtImage::create([
            'art_id' => $artId,
            'image' => $imageFileName
        ]);
    }

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

    public function deleteByArtId($artId)
    {
        $images = CreativeArtImage::where('art_id', $artId)->get();
        foreach ($images as $image) {
            $this->delete($image->id);
        }
        return true;
    }
}
