<?php

namespace App\Models;

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

/**
 * @property int $id
 * @property int $product_id
 * @property bool $is_active
 * @property array<array-key, mixed>|null $metadata
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property-read string $category_label
 * @property-read string $period_type_label
 * @property-read \App\Models\Product|null $product
 *
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost active()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost byCategory($category)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost byPeriodType($periodType)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost whereIsActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost whereMetadata($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ServiceCost whereUpdatedAt($value)
 *
 * @mixin \Eloquent
 */
class ServiceCost extends Model
{
    use HasFactory;

    protected $fillable = [
        'product_id',
        'is_active',
        'metadata',
    ];

    protected $casts = [
        'is_active' => 'boolean',
        'metadata' => 'array',
    ];

    // Period keys
    const PERIOD_DAILY = 'daily';

    const PERIOD_MONTHLY = 'monthly';

    const PERIOD_YEARLY = 'yearly';

    /**
     * Get period type options
     */
    public static function getPeriodTypeOptions(): array
    {
        return [
            self::PERIOD_DAILY => __('models.service_cost.period_daily'),
            self::PERIOD_MONTHLY => __('models.service_cost.period_monthly'),
            self::PERIOD_YEARLY => __('models.service_cost.period_yearly'),
        ];
    }

    /**
     * Get category options
     */
    public static function getCategoryOptions(): array
    {
        return [];
    }

    /**
     * Get period type label
     */
    public function getPeriodTypeLabelAttribute(): string
    {
        return '';
    }

    /**
     * Get category label
     */
    public function getCategoryLabelAttribute(): string
    {
        return '';
    }

    /**
     * Check if cost is currently active
     */
    public function isCurrentlyActive(): bool
    {
        return (bool) $this->is_active;
    }

    /**
     * Calculate monthly cost
     */
    public function getMonthlyCost(): float
    {
        return 0.0;
    }

    /**
     * Calculate yearly cost
     */
    public function getYearlyCost(): float
    {
        return 0.0;
    }

    /**
     * Scope for active costs
     */
    public function scopeActive($query)
    {
        return $query->where('is_active', true);
    }

    /**
     * Scope for costs by category
     */
    public function scopeByCategory($query, $category)
    {
        return $query;
    }

    /**
     * Scope for costs by period type
     */
    public function scopeByPeriodType($query, $periodType)
    {
        return $query;
    }

    /**
     * İlişkiler
     */
    public function product()
    {
        return $this->belongsTo(Product::class, 'product_id');
    }

    public function currency()
    {
        return null;
    }
}
