<?php

namespace App\Models;

use App\Traits\HasImages;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AppBannerSetting extends Model
{
    use HasFactory, HasImages;

    public const IMAGE_UPLOAD_TO = 'uploads/app-banner-settings';
    public const IMAGE_SIZE_SMALL = 'small';
    public const IMAGE_SIZE_LARGE = 'large';
    public const IMAGE_KEY_APP_STORE = 'app_store';
    public const IMAGE_KEY_PLAY_STORE = 'play_store';

    protected $table = 'app_banner_settings';

    protected $fillable = [
        'title',
        'description',
        'show_app_store_button',
        'show_play_store_button',
        'app_store_link',
        'play_store_link',
    ];

    protected $casts = [
        'show_app_store_button' => 'bool',
        'show_play_store_button' => 'bool',
        'created_at' => 'datetime:d-m-Y H:i:s',
        'updated_at' => 'datetime:d-m-Y H:i:s',
    ];

    protected $appends = [
        'image',
        'app_store_image',
        'play_store_image',
    ];

    public function getImageAttribute(): ?string
    {
        return $this->getThumbnail(null, self::IMAGE_SIZE_LARGE);
    }

    public function getAppStoreImageAttribute(): ?string
    {
        return $this->getThumbnail('app_store', self::IMAGE_SIZE_LARGE);
    }

    public function getPlayStoreImageAttribute(): ?string
    {
        return $this->getThumbnail('play_store', self::IMAGE_SIZE_LARGE);
    }
}
