<?php

declare(strict_types=1);

namespace App\Models\Market;

use App\Models\Model;
use App\Models\User;

class ProductTransactionSession extends Model
{
    protected ?string $table = 'prd_trx_ses';

    /**
     * The primary key for the model.
     */
    protected $primaryKey = 'id';

    /**
     * Indicates if the IDs are auto-incrementing.
     */
    public $incrementing = true;

    /**
     * The "type" of the primary key.
     */
    protected $keyType = 'int';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [
        'hashkey',
        'name',
        'description',
        'logs',
        'remarks',
        'created_by',
        'updated_by',
        'created_for',
        'subtype',
        'additionaldata',
        'category',
        'store_id',
        'status',
        'is_void',
        'last_total_price',
        'last_total_discount',
        'notes',

    ];

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

    /**
     * Relationships.
     */
    public function transactions()
    {
        return $this->hasMany(ProductTransaction::class, 'transactionsessionhash', 'hashkey');
    }

    public function store()
    {
        return $this->belongsTo(Store::class, 'store_id');
    }

    public function creator()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updater()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }

    public function createdFor()
    {
        return $this->belongsTo(User::class, 'created_for');
    }
}
