<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Company extends Model
{
    use HasFactory;
    use SoftDeletes;

    protected $table = 'companies';
    
    protected $fillable = 
    [
        'name',
        'contact_person_name',
        'company_tel',
        'service_charge',
        'company_tel2',
        'street_address',
        'overhead_charge',
        'overhead_type',
        'type',
        'city',
        'state',
        'zipcode',
        'email_address',
        'is_banned',
        'enable_borrowing',
        'contact_person_no',
        'is_freezed', 
        'date_freezed',
        'last_read_request_notifications_at',
    ];  

    public static function companyInfo($company_id) 
    {
        return Company::select('name','street_address','city','state','zipcode', 'company_tel', 'contact_person_name')->where('id', $company_id)->first();
    }

    public function settings()
    {
        return $this->hasMany(CompanySettings::class, 'company_id', 'id');
    }

    public function company_expertises() 
    {
        return $this->hasMany('App\Models\CompanyExpertise', 'company_id', 'id')
            ->join('expertises', 'expertises.id', '=', 'company_expertises.expertise_id')
            ->orderBy('expertises.name', 'asc');
    }
}
