<?php

namespace App\Models;

use App\Traits\Currencies;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class RoomType extends Model
{
    use HasFactory, Currencies;
    protected $fillable = ['name','code', 'capacity','status','is_double'];

    public function rooms()
    {
        return $this->hasMany(Room::class, 'type_id');
    }

    public function service()
    {
        return $this->hasOne(Service::class);
    }

    public function Tickets()
    {
        return $this->hasManyThrough(Ticket::class, TravelSegment::class, 'room_type_id', 'segment_id')->withoutGlobalScopes();
    }

    public function mix($back=false){
        // dd( $this->tickets_count,$this->service->id);
        $capacity = $this->rooms_count * $this->capacity - $this->tickets_count;
        return [
            'id' => $this->id,
            'name' => $this->name,
            'is_double' =>$this->is_double,
            'price' => $this->convertCurrency($back?$this->service->price_two:$this->service->price),
            'capacity' => $capacity,
            'fake_capacity' => $capacity>intval(config('booking.fake_capacity'))?config('booking.fake_capacity'):$capacity,
            'service_id' => $this->service->id
        ];
    }
}
