<?php

namespace App\Repositories;

use App\Enums\MemberStatusEnum;

use App\Models\Dependent;
use Illuminate\Database\Eloquent\Model;

class DependentRepository extends BaseRepository
{
    public function __construct(Dependent $model)
    {
        parent::__construct($model);
    }

    public function statusToggle($model, string $reason = '', $column = 'status', array $relations = []): array
    {
        $newStatus = $model->status === MemberStatusEnum::PENDING->value
            ? MemberStatusEnum::ACTIVE->value
            : MemberStatusEnum::PENDING->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 ? MemberStatusEnum::ACTIVE->value : MemberStatusEnum::PENDING->value;
        $updated = $this->model->whereIn('id', $ids)->update([$column => $value]);
        return [
            'updated'         => $updated,
            'skipped'         => 0,
            'skipped_ids'     => [],
            'skipped_records' => [],
        ];
    }
}
