<?php

namespace Licenzo\Model;

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

use Licenzo\Framework\Database\Model;

/**
 * LicenseProduct Model
 *
 * Represents the association between a License and a Product
 */
class LicenseProduct extends Model
{
    /**
     * Table name
     */
    protected $table = 'licenzo_license_products';

    /**
     * Primary key
     */
    protected $primaryKey = 'id';

    /**
     * Fillable attributes
     */
    protected $fillable = [
        'license_id',
        'product_id',
        'variation_id',
        'product_name',
        'variation_name',
        'started_at',
        'expire_date',
        'activation_count',
        'created_at',
        'updated_at'
    ];

    /**
     * Attributes that should be cast
     */
    protected $casts = [
        'id'               => 'int',
        'license_id'       => 'int',
        'product_id'       => 'int',
        'variation_id'     => 'int',
        'activation_count' => 'int',
        'started_at'       => 'datetime',
        'expire_date'      => 'datetime',
        'created_at'       => 'datetime',
        'updated_at'       => 'datetime'
    ];

    /**
     * Relationship: belongs to a License
     */
    public function license()
    {
        return $this->belongsTo(License::class, 'license_id');
    }

    /**
     * Relationship: belongs to a Product
     */
    public function product()
    {
        return $this->belongsTo(Product::class, 'product_id');
    }

    public function variation()
    {
        return $this->belongsTo(ProductVariation::class, 'variation_id');
    }
}
