<?php

namespace App\Models;

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

class MerchantEmployee extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'merchant_employees';

    protected $fillable = [
        'merchant_uuid',
        'user_id',
        'name',
        'surname',
        'email',
        'phone',
        'profile_picture',
        'role',
        'status',
        'is_main_user',
        'permissions',
        'qr_code_key',
        'pin',
    ];

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

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

    /**
     * Generate QR code key from user_id and PIN
     */
    public function generateQrCodeKey(string $pin): string
    {
        $serverHash = env('SERVER_HASH', 'default-server-hash-change-in-production');
        return hash('sha256', $this->user_id . $serverHash . $pin);
    }
}


