<?php

namespace App\Repositories;

use App\Enums\ParkingStatusEnum;
use App\Models\Parking;
use Illuminate\Database\Eloquent\Model;

class ParkingRepository extends BaseRepository
{
    public function __construct(Parking $model)
    {
        parent::__construct($model);
    }

    public function statusToggle($model, string $reason = '', $column = 'status', array $relations = []): array
    {
        $newStatus = $model->status === ParkingStatusEnum::ACTIVE->value
            ? ParkingStatusEnum::INACTIVE->value
            : ParkingStatusEnum::ACTIVE->value;

        $model->update(['status' => $newStatus]);

        return [
            'success'   => true,
            'message'   => __('app.status_updated'),
            'relations' => [],
        ];
    }

    public function bulkStatus(array $ids, bool $status, string $column = 'status', array $relations = [])
    {
        $value = $status ? ParkingStatusEnum::ACTIVE->value : ParkingStatusEnum::INACTIVE->value;
        $updated = $this->model->whereIn('id', $ids)->update([$column => $value]);
        return [
            'updated'         => $updated,
            'skipped'         => 0,
            'skipped_ids'     => [],
            'skipped_records' => [],
        ];
    }
}
