<?php

namespace App\Models\Claim;

use App\Models\Institution\Institution;
use App\Trait\BelongsToSolicitor;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class CareSetting extends Model {
    public $fillable = [
        'solicitor_id',
        'claim_id',
        'institution_id',
        'area_id',
        'dates',
        'people_involved',
        'statement'
    ];

    use BelongsToSolicitor, SoftDeletes;

    public function institution() {
        return $this->belongsTo(Institution::class);
    }

    public function area() {
        return $this->belongsTo(Area::class);
    }

    public function claim() {
        return $this->belongsTo(Claim::class);
    }

    /** The area/suburb name, or null. */
    public function areaName(): ?string
    {
        return $this->area?->name;
    }

    /** The local authority (the area's council) name, or null. */
    public function localAuthority(): ?string
    {
        return $this->area?->council?->name;
    }

    public function statementHistory() {
        return $this->hasMany(CareSettingStatementHistory::class)->latest();
    }
}
