<?php
declare(strict_types=1);

namespace App\Core\Events;

final class MemberCreated extends Event
{
    public function __construct(
        public readonly int $memberId,
        public readonly string $fullNameAr,
        public readonly string $status,
        public readonly int $branchId,
    ) {}

    public static function eventName(): string
    {
        return 'member.created';
    }

    public function toArray(): array
    {
        return [
            'id' => $this->memberId,
            'member_id' => $this->memberId,
            'full_name_ar' => $this->fullNameAr,
            'status' => $this->status,
            'branch_id' => $this->branchId,
        ];
    }

    public static function from(array $data): static
    {
        return new self(
            memberId: (int) ($data['member_id'] ?? $data['id'] ?? 0),
            fullNameAr: (string) ($data['full_name_ar'] ?? ''),
            status: (string) ($data['status'] ?? 'potential'),
            branchId: (int) ($data['branch_id'] ?? 0),
        );
    }
}
