<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Package extends Model
{
    use HasFactory;

    // table ka naam (safety ke liye)
    protected $table = 'packages';

    // mass assignment ke liye allowed columns
    protected $fillable = [
        'package_id',
        'tab',
        'label',
        'name',
        'photo',
        'price',
        'validity',
      
        'commission_with_avg_amount',
       
        'ref1',
        'ref2',
        'ref3',
        'status',
        'is_default',
        'desc',
        'daily_watch_limit', // naya column
    ];

    /**
     * 🔹 Daily earning (total ÷ validity)
     */
    public function getDailyEarningAttribute()
    {
        return $this->validity > 0
            ? (float) $this->commission_with_avg_amount / $this->validity
            : 0.0;
    }

    /**
     * 🔹 Per video earning (daily ÷ daily_watch_limit)
     */
    public function getPerVideoEarningAttribute()
    {
        return $this->daily_watch_limit > 0
            ? $this->daily_earning / $this->daily_watch_limit
            : 0.0;
    }
}
