<?php
declare(strict_types=1);

namespace App\Controllers;

use App\Core\Controller;
use App\Core\Response;
use App\Models\CurrencyModel;

class CurrencyController extends Controller
{
    private CurrencyModel $currencyModel;

    public function __construct()
    {
        $this->currencyModel = new CurrencyModel();
    }

    public function index(): void
    {
        $tenantId = (int) $_REQUEST['tenant_id'];
        Response::success($this->currencyModel->getAll($tenantId));
    }

    public function store(): void
    {
        $tenantId = (int) $_REQUEST['tenant_id'];
        $data = $this->getJsonBody();
        $data['tenant_id'] = $tenantId;

        if ($this->currencyModel->create($data)) {
            Response::success([], 'Currency added');
        }
        Response::error('Failed to add');
    }

    public function delete(int $id): void
    {
        if ($this->currencyModel->delete($id)) {
            Response::success([], 'Currency removed');
        }
        Response::error('Failed to remove');
    }
}
