<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Builder;
/**
 * Class Address
 * @package App\Models
 *
 * @property int $country_id
 * @property int $company_id
 * @property int $state_id
 * @property int $district_id
 * @property string $postcode
 * @property string $street_one
 * @property string $street_two
 * @property int $billing_type
 */
class Address extends AbstractModel
{
    use SoftDeletes;

    protected $table = 'addresses';

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'deleted_at' => 'datetime',
        ];
    }

    /**
     * @return BelongsTo
     */
    public function country(): BelongsTo
    {
        return $this->BelongsTo(Country::class, 'country_id', 'id');
    }

    /**
     * @return BelongsTo
     */
    public function company(): BelongsTo
    {
        return $this->BelongsTo(Company::class, 'company_id', 'id');
    }

    /**
     * @return BelongsTo
     */
    public function state(): BelongsTo
    {
        return $this->BelongsTo(State::class, 'state_id', 'id');
    }

    /**
     * @return BelongsTo
     */
    public function district(): BelongsTo
    {
        return $this->BelongsTo(District::class, 'district_id', 'id');
    }

    /**
     * @param Builder $query
     * @return Builder
     */
    public function scopeDefault(Builder $query)
    {
        return $query->where('billing', '=', true)->first();
    }
}
