<?php

namespace App\Admin\Repositories;

use App\Models\BaseProductImage as Model;
use Dcat\Admin\Repositories\EloquentRepository;
use Carbon\Carbon;

class BaseProductImage extends EloquentRepository
{
    /**
     * Model.
     *
     * @var string
     */
    protected $eloquentClass = Model::class;


    public static function deleteByProductId($productId)
    {
        Model::where('product_id', $productId)->delete();
    }

    public static function saveProductImages($productId, $imageUrls)
    {
        if (empty($productId) || empty($imageUrl)) {
            return false;
        }
        // 准备数据集合
        $data = [];
        foreach ($imageUrls as $imageUrl) {
            $data[] = [
                'product_id' => $productId,
                'image_url' => $imageUrl,
                'created_at' => Carbon::now(),
                'updated_at' => Carbon::now(),
            ];
        }
        // 批量插入
        return Model::insert($data);
    }


}
