<?php

namespace App\Controllers\API;

use App\Controllers\BaseController;
use App\Models\ServiceModel;
use App\Libraries\ResponseFormatter;

class ServiceController extends BaseController
{
    protected $serviceModel;

    public function __construct()
    {
        $this->serviceModel = new ServiceModel();
    }

    // 📌 GET ALL SERVICES
    public function index()
    {
        $services = $this->serviceModel->findAll();

        return $this->response->setJSON(
            ResponseFormatter::success($services)
        );
    }
    // ➕ CREATE
public function create()
{
    $input = $this->request->getJSON(true);

    $this->serviceModel->insert($input);

    return $this->response->setJSON(
        ResponseFormatter::success(null, 'Service berhasil ditambahkan')
    );
}

// ✏️ UPDATE
public function update($id)
{
    $input = $this->request->getJSON(true);

    $this->serviceModel->update($id, $input);

    return $this->response->setJSON(
        ResponseFormatter::success(null, 'Service berhasil diupdate')
    );
}

// ❌ DELETE
public function delete($id)
{
    $this->serviceModel->delete($id);

    return $this->response->setJSON(
        ResponseFormatter::success(null, 'Service berhasil dihapus')
    );
}
}