<?php

namespace Modules\User\Models;


use App\Models\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Config;
use SimpleSoftwareIO\QrCode\Facades\QrCode;

class UserChannel extends Model
{

    public function getOfficialCodeBase64Attribute(): string
    {
        $url = Config::get('user.invite_code.url').'?channel='.$this->code;

        return 'data:image/png;base64,'.base64_encode(QrCode::format('png')
                ->size(300)
                ->margin(3)
                ->generate($url));
    }

    public function users(): HasMany
    {
        return $this->hasMany(User::class,'channel_id');
    }
}
