<?php

namespace App\Models\Rd;

use App\Models\User;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class CmSong extends Model
{
    use BelongsToTenant, SoftDeletes;

    protected $table = 'cm_songs';

    protected $fillable = [
        'tenant_id',
        'user_id',
        'company_name',
        'industry',
        'lyrics',
        'audio_path',
        'options',
    ];

    protected $casts = [
        'options' => 'array',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function getOption(string $key, mixed $default = null): mixed
    {
        return data_get($this->options, $key, $default);
    }

    public function setOption(string $key, mixed $value): void
    {
        $options = $this->options ?? [];
        data_set($options, $key, $value);
        $this->options = $options;
    }

    public function getMood(): string
    {
        return $this->getOption('mood', '-');
    }

    public function getDuration(): int
    {
        return $this->getOption('duration', 15);
    }
}
