<?php

namespace Modules\VetClinic\Entities;

use Illuminate\Database\Eloquent\Model;

class VcSoapOption extends Model
{
    protected $table = 'vc_soap_options';
    protected $guarded = ['id'];

    public function scopeActive($query)
    {
        return $query->where('status', 'active');
    }

    public function scopeSection($query, string $section)
    {
        return $query->where('section', $section);
    }

    /** Return all active options for a section/species combo merged with system defaults */
    public static function forBusiness(int $businessId, string $section, string $species = 'all'): \Illuminate\Support\Collection
    {
        return static::active()
            ->section($section)
            ->where(function ($q) use ($businessId) {
                $q->whereNull('business_id')->orWhere('business_id', $businessId);
            })
            ->where(function ($q) use ($species) {
                $q->where('species', 'all')->orWhere('species', $species);
            })
            ->orderBy('sort_order')
            ->orderBy('label')
            ->get();
    }
}
