<?php

namespace Modules\Main\Models\Company;

use Illuminate\Database\Eloquent\SoftDeletes;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Modules\Payment\Traits\Paymentable;
use Modules\Main\Models\City;
use Modules\Bitrix\Traits\Bitrixable;


class Company extends Model
{
    use HasFactory;
    use SoftDeletes;
    use Paymentable;
    use Bitrixable;
    const STATUS_NEW      = 'new';
    const STATUS_ACCEPTED = 'accepted';
    const STATUS_DECLINED = 'declined';
    protected $fillable = [
        'type',
        'name',
        'full_name',
        'inn',
        'email',
        'phone',
        'address',
        'legal_address',
        'details',
        'status',
        'secret',
        'city_id'
    ];

    protected $casts = [
        'details' => 'array',
        'type'    => CompanyType::class
    ];

    public function city()
    {
        return $this->belongsTo(City::class);
    }

    protected static function booted()
    {
        static::created(function (Company $company)
        {
            $details = new Details($company);
            $details->create();
        });
    }
}
