<?php

namespace App\Enum\Contact;

enum MessageStatus: string
{
    case DRAFT = 'draft';
    case QUEUED = 'queued';
    case SENDING = 'sending';
    case SENT = 'sent';
    case DELIVERED = 'delivered';
    case OPENED = 'opened';
    case CLICKED = 'clicked';
    case BOUNCED = 'bounced';
    case DROPPED = 'dropped';
    case SPAM_REPORT = 'spam_report';
    case DEFERRED = 'deferred';
    case FAILED = 'failed';
    case UNDELIVERED = 'undelivered';
    case SUPPRESSED = 'suppressed';

    public function label(): string
    {
        return match ($this) {
            self::DRAFT => 'Draft',
            self::QUEUED => 'Queued',
            self::SENDING => 'Sending',
            self::SENT => 'Sent',
            self::DELIVERED => 'Delivered',
            self::OPENED => 'Opened',
            self::CLICKED => 'Clicked',
            self::BOUNCED => 'Bounced',
            self::DROPPED => 'Dropped',
            self::SPAM_REPORT => 'Spam Report',
            self::DEFERRED => 'Deferred',
            self::FAILED => 'Failed',
            self::UNDELIVERED => 'Undelivered',
            self::SUPPRESSED => 'Suppressed',
        };
    }

    public function color(): string
    {
        return match ($this) {
            self::DRAFT => 'secondary',
            self::QUEUED, self::SENDING => 'info',
            self::SENT => 'primary',
            self::DELIVERED, self::OPENED, self::CLICKED => 'success',
            self::DEFERRED => 'warning',
            self::BOUNCED, self::DROPPED, self::SPAM_REPORT, self::FAILED, self::UNDELIVERED => 'danger',
            self::SUPPRESSED => 'dark',
        };
    }

    public function isTerminalSuccess(): bool
    {
        return in_array($this, [self::DELIVERED, self::OPENED, self::CLICKED], true);
    }

    public function isTerminalFailure(): bool
    {
        return in_array($this, [
            self::BOUNCED, self::DROPPED, self::SPAM_REPORT,
            self::FAILED, self::UNDELIVERED, self::SUPPRESSED,
        ], true);
    }

    public function rank(): int
    {
        return match ($this) {
            self::DRAFT => 0,
            self::QUEUED => 10,
            self::SENDING => 20,
            self::SENT => 30,
            self::DEFERRED => 35,
            self::DELIVERED => 40,
            self::OPENED => 50,
            self::CLICKED => 60,
            self::BOUNCED, self::DROPPED, self::SPAM_REPORT,
            self::FAILED, self::UNDELIVERED, self::SUPPRESSED => 100,
        };
    }
}
