<?php

namespace App\Models\Concerns;

use App\Enums\ContactMessageStatus;
use App\Enums\ContentStatus;
use App\Enums\ReplyStatus;
use Illuminate\Database\Eloquent\Casts\Attribute;

trait HasStatusLabels
{
    /**
     * @return Attribute<string, never>
     */
    protected function statusLabel(): Attribute
    {
        return Attribute::get(function (): string {
            return [
                ContentStatus::Published->value => ContentStatus::Published->label(),
                ContentStatus::Archived->value => ContentStatus::Archived->label(),
                ContentStatus::Draft->value => ContentStatus::Draft->label(),
                ContactMessageStatus::New->value => ContactMessageStatus::New->label(),
                ContactMessageStatus::Read->value => ContactMessageStatus::Read->label(),
                ContactMessageStatus::Replied->value => ContactMessageStatus::Replied->label(),
                ContactMessageStatus::Processed->value => ContactMessageStatus::Processed->label(),
                ReplyStatus::Sending->value => ReplyStatus::Sending->label(),
                ReplyStatus::Sent->value => ReplyStatus::Sent->label(),
                ReplyStatus::Failed->value => ReplyStatus::Failed->label(),
            ][$this->status] ?? (string) $this->status;
        });
    }

    public function scopePublished($query)
    {
        return $query->where('status', ContentStatus::Published->value);
    }

    public function scopeArchived($query)
    {
        return $query->where('status', ContentStatus::Archived->value);
    }
}
