<?php

namespace App\Services;

use App\Models\ActivityLog;
use App\Models\OnlineStatus;
use App\Repositories\OnlineStatusRepository;

class OnlineStatusService
{
    public function __construct(protected OnlineStatusRepository $repository) {}

    public function create(array $data): OnlineStatus
    {
        $status = $this->repository->create($data);

        ActivityLog::create([
            'user_id' => auth()->id(),
            'action' => 'online_status_created',
            'resource_type' => OnlineStatus::class,
            'resource_id' => $status->id,
            'description' => 'Online status created for customer ID '.$status->customer_id,
        ]);

        return $status;
    }

    public function update(OnlineStatus $status, array $data): bool
    {
        $result = $this->repository->update($status, $data);

        ActivityLog::create([
            'user_id' => auth()->id(),
            'action' => 'online_status_updated',
            'resource_type' => OnlineStatus::class,
            'resource_id' => $status->id,
            'description' => 'Online status updated for customer ID '.$status->customer_id,
        ]);

        return $result;
    }

    public function delete(OnlineStatus $status): bool
    {
        $result = $this->repository->delete($status);

        ActivityLog::create([
            'user_id' => auth()->id(),
            'action' => 'online_status_deleted',
            'resource_type' => OnlineStatus::class,
            'resource_id' => $status->id,
            'description' => 'Online status deleted for customer ID '.$status->customer_id,
        ]);

        return $result;
    }
}
