<?php

namespace App\Models\Claim;

use App\Casts\DOB;
use App\Casts\EmailAddress;
use App\Casts\PhoneNumber;
use App\Casts\Postcode;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Beneficiary extends Model {
    protected $fillable = [
        'claim_id',
        'first_name',
        'middle_name',
        'surname',
        'date_of_birth',
        'address_line_1',
        'address_line_2',
        'address_line_3',
        'address_line_4',
        'postcode',
        'email',
        'telephone',
    ];

    protected $casts = [
        'postcode' => Postcode::class,
        'telephone' => PhoneNumber::class,
        'email' => EmailAddress::class,
        'date_of_birth' => DOB::class,
    ];

    use HasFactory;

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

    public function getFullNameAttribute(): string {
        return collect([
            $this->first_name,
            $this->middle_name,
            $this->surname,
        ])->filter()->implode(' ');
    }
}
