<?php

namespace App\Models\Defendant;

use App\Trait\HasDocuments;
use App\Trait\HasHistory;
use App\Trait\HasNotes;
use App\Trait\HasSlug;
use Illuminate\Database\Eloquent\Model;

class Defendant extends Model {
    protected $table = 'defendants';

    protected $fillable = [
        'slug',
        'display_name',
    ];

    use HasNotes, HasHistory, HasSlug, HasDocuments;

    public function addresses() {
        return $this->hasMany(DefendantContact::class)->whereNotNull('postcode');
    }

    public function defendant() {
        return $this->belongsTo(Defendant::class);
    }

    public function phoneNumbers() {
        return $this->hasMany(DefendantContact::class)->whereNotNull('phone_number');
    }

    public function emailAddresses() {
        return $this->hasMany(DefendantContact::class)->whereNotNull('email_address');
    }

    public function contacts() {
        return $this->hasMany(DefendantContact::class);
    }

    public function getDocumentStoragePath(): string {
        return 'defendants/' . $this->getSlugTargetAttribute();
    }
}
