<?php

namespace App\Http\Controllers\Concerns;

use App\Models\Admin;
use App\Models\Merchant;
use Illuminate\Http\Request;

trait ResolvesSiteContext
{
    protected function siteId(Request $request): int
    {
        return (int) ($request->session()->get('admin_site_id') ?: $request->session()->get('admin_merchant_id'));
    }

    protected function site(Request $request): Merchant
    {
        return Merchant::query()->findOrFail($this->siteId($request));
    }

    protected function siteAdmin(Request $request): Admin
    {
        return Admin::query()->findOrFail((int) $request->session()->get('admin_id'));
    }
}
