<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;

/**
 * @package App\Models
 * @property int $id
 * @property array $name
 * @property array $description
 * @property string $video_url
 * @property string $image
 * @property string $status
 * @property bool $is_price
 *
 * @property Region[] $regions
 * @property Status $getStatus
 *
 */
class Partner extends Model
{

    protected $fillable = [
        'name',
        'description',
        'video_url',
        'image',
        'status',
        "position",
        'is_price',
    ];

    protected $casts = [
        'is_price' => 'boolean',
        'description' => 'array',
        'name' => 'array',
    ];

    //? Statuses: new, soon, published
    public function getStatus()
    {
        return $this->belongsTo(Status::class, 'status', 'slug');
    }

    /**
     * @return string
     */
    public function getImage(): string
    {
        if (!empty($this->image)) {
            if (in_array(env('FILESYSTEM_DISK'), ['s3', 'minio'])) {
                return Storage::temporaryUrl(
                    $this->image,
                    Date::now()->addMinutes(5)
                );
            }

            return (string) $this->image;
        }

        return (string) 'images/no_brend.png';
    }

    public function getName(): string
    {
        if (App::isLocale('ru')) {
            return (string) $this->name['ru'];
        }

        return (string) $this->name['uz'];
    }

    public function getDescription(): string
    {
        if (App::isLocale('ru')) {
            return (string) $this->description['ru'];
        }

        return (string) $this->description['uz'];
    }
}
