<?php
declare(strict_types=1);

namespace App\Controllers;

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

class TaxRateController extends Controller
{
    private TaxRateModel $taxRateModel;

    public function __construct()
    {
        $this->taxRateModel = new TaxRateModel();
    }

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

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

        if ($this->taxRateModel->create($data)) {
            Response::success([], 'Tax rate created');
        }
        Response::error('Fail');
    }

    public function delete(int $id): void
    {
        if ($this->taxRateModel->delete($id)) {
            Response::success([], 'Removed');
        }
        Response::error('Fail');
    }
}
