<?php

declare(strict_types=1);

namespace ImovelZapAi\Publishing\Application\Data;

use ImovelZapAi\Publishing\Domain\Enums\TenantPublishingPlan;
use ImovelZapAi\Publishing\Domain\Enums\TenantPublishingStatus;
use ImovelZapAi\Publishing\Infrastructure\Persistence\Eloquent\TenantPublishingConfigModel;
use ImovelZapAi\Tenancy\Infrastructure\Persistence\Eloquent\TenantModel;

final readonly class TenantPublishingConfigData
{
    public function __construct(
        public string $tenantId,
        public string $companyName,
        public ?string $logoUrl,
        public ?string $email,
        public ?string $telephone,
        public string $xmlFeedUrl,
        public TenantPublishingStatus $publishingStatus,
        public TenantPublishingPlan $plan,
        public bool $channelProEnabled,
    ) {}

    public static function fromModels(
        TenantModel $tenant,
        TenantPublishingConfigModel $config,
        string $xmlFeedUrl,
    ): self {
        return new self(
            tenantId: (string) $tenant->id,
            companyName: $config->company_name ?? $tenant->name,
            logoUrl: $config->logo_url,
            email: $config->email,
            telephone: $config->telephone,
            xmlFeedUrl: $xmlFeedUrl,
            publishingStatus: $config->publishing_status,
            plan: $config->plan,
            channelProEnabled: $config->channel_pro_enabled,
        );
    }

    public function publishingStatusLabel(): string
    {
        return $this->publishingStatus->label();
    }

    public function planLabel(): string
    {
        return $this->plan->label();
    }

    public function isPublishingActive(): bool
    {
        return $this->publishingStatus === TenantPublishingStatus::Active;
    }

    public function channelProLabel(): string
    {
        return $this->channelProEnabled ? 'Habilitado' : 'Desabilitado';
    }
}
