<?php

namespace App\Repositories;

use App\Models\Coach;
use App\Traits\ImageTrait;
use Illuminate\Database\Eloquent\Model;

class CoachRepository extends BaseRepository
{
    use ImageTrait;

    public function __construct(Coach $model)
    {
        parent::__construct($model);
    }

    public function create(array $attributes): Model
    {
        $this->addImage($attributes, 'image', 'coaches');
        return parent::create($attributes);
    }

    public function update(Model $model, array $attributes): bool
    {
        $this->updateImage($attributes, 'image', 'coaches', $model);
        return parent::update($model, $attributes);
    }

    public function delete(Model $model, array $relations = []): array
    {
        $this->deleteImage($model, 'image');
        return parent::delete($model, $relations);
    }

    public function bulkDelete(array $ids, array $relations = [])
    {
        $models = $this->model->whereIn('id', $ids)->get();
        foreach ($models as $model) {
            $this->deleteImage($model, 'image');
        }
        return parent::bulkDelete($ids, $relations);
    }
}
