<?php

namespace App\Models\Payment;

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

class ApiKeyHalkbank extends Model
{
    use HasFactory;

    /**
     * Table name
     *
     * @var string
     */
    protected $table = 'api_key_halkbank';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'order_number',
        'billing_username',
        'billing_password',
    ];

    /**
     * Generate unique order number
     */
    public static function generateOrderNumber($resource): int
    {
        $order_number = static::firstOrCreate([
            'billing_username' => $resource->billing_username ?? 'asdasd',
            'billing_password' => $resource->billing_password ?? 'asdasd',
        ], ['order_number' => '01122017270']);

        $order_number->update([
            'order_number' => $order_number->order_number + 1,
        ]);

        return $order_number->order_number;
    }
}
