<?php

/**
 * Application Service Provider
 *
 * @package Licenzo\ServiceProvider
 */

namespace Licenzo\ServiceProvider;

use Licenzo\Framework\Foundation\ServiceProvider;
use Licenzo\Framework\Database\Query\Builder as QueryBuilder;
use Licenzo\Framework\Pagination\AbstractPaginator;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Simple application service provider
 * Only handles QueryBuilder binding as 'db'
 */
class AppServiceProvider extends ServiceProvider
{
    /**
     * Register services
     */
    public function register()
    {
        // Register QueryBuilder as 'db' for raw queries like $app->db()->table('table_name')
        $this->app->singleton('db', function () {
            return new QueryBuilder();
        });

        $this->app->alias('db', \Licenzo\Framework\Database\Query\Builder::class);



        $this->app->singleton(\Licenzo\Services\LicenseService::class, function () {
            return new \Licenzo\Services\LicenseService();
        });
    }

    /**
     * Boot services
     */
    public function boot()
    {
        \Licenzo\App::setInstance($this->app);

        AbstractPaginator::currentPageResolver(function ($pageName = 'page', $default = 1) {
            $request = $this->app->make('request');
            return $request->input($pageName, $default);
        });
    }
}
