<?php

namespace App\Models\Dsar;

use App\Trait\BelongsToSolicitor;
use App\Models\User\User;
use Illuminate\Database\Eloquent\Model;

class DsarResponse extends Model {

    use BelongsToSolicitor;

    protected $fillable = [
        'solicitor_id',
        'dsar_id',
        'user_id',
        'type',
        'notes',
        'received_at',
        'is_flagged',
    ];

    protected $casts = [
        'received_at' => 'datetime',
        'is_flagged'  => 'boolean',
    ];

    public static array $flaggedTypes = [
        'pushback',
        'wrong_recipient',
        'unknown_client',
    ];

    public function dsar() {
        return $this->belongsTo(Dsar::class);
    }

    public function user() {
        return $this->belongsTo(User::class);
    }

    public function getTypeLabelAttribute(): string {
        return match($this->type) {
            'pushback'        => 'Pushback',
            'partial'         => 'Partial Response',
            'full'            => 'Full Response',
            'wrong_recipient' => 'Wrong Recipient',
            'unknown_client'  => 'Unknown Client',
            default           => ucfirst($this->type),
        };
    }

    public function getTypeBadgeClassAttribute(): string {
        return match($this->type) {
            'pushback'        => 'bg-danger',
            'partial'         => 'bg-warning text-dark',
            'full'            => 'bg-success',
            'wrong_recipient' => 'bg-secondary',
            'unknown_client'  => 'bg-dark',
            default           => 'bg-info',
        };
    }
}
