<?php

namespace App\Models\Tenancy;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;

class Procedure extends Model
{
    protected $hidden = [
        'doctor_max_sale',
        'ncsp',
        'status',
        'creator_id',
        'technician',
        'options',
        'insurance_price',
        'insurance_id',
        'insurance_sale',
        'expense_enabled',
        'expense_type',
        'purpose',
        'expense_amount',
        'affects_doctor_salary',
        'deduct_client_amount',
        'for_residents',
        'online',
    ];

    protected $casts = [
        'online' => 'boolean',
    ];

    protected $appends = [
        'price_old',
    ];

    public function scopeOnline(Builder $query)
    {
        $query->where('online', true);
    }

    public function scopeWithStatus(Builder $query, string $status)
    {
        $query->where('status', $status);
    }

    protected function priceOld(): Attribute
    {
        return Attribute::make(
            get: fn (mixed $value, array $attributes) => $attributes['price']
        );
    }

    protected function price(): Attribute
    {
        return Attribute::make(
            get: fn (mixed $value, array $attributes) => $attributes['price'] * (100 - $attributes['sale']) / 100
        );
    }
}
