<?php
namespace App\Domain\PaymentGateway\Models;

use App\Models\User;
use App\Models\Model;
use Illuminate\Support\Str;

class PaymentGatewayOrder extends Model
{
    const TYPE_INTERKASSA_NAME = "interkassa";
    const TYPE_UNITPAY_NAME = "unitpay";
    const TYPE_QIWI_NAME = "qiwi";
    const TYPE_YOO_NAME = "yookassa";

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

    public static function interkassa($amount)
    {
        $paymentGatewayOrder = new PaymentGatewayOrder;
        $paymentGatewayOrder->user_id = auth()->user()->id;
        $paymentGatewayOrder->amount = $amount;
        $paymentGatewayOrder->status = 0; // 0 - created/ 1- success/ 2-error/ 3-pending
        $paymentGatewayOrder->type = self::TYPE_INTERKASSA_NAME;
        $paymentGatewayOrder->save();

        return $paymentGatewayOrder;
    }

    public static function unitpay($amount)
    {
        $paymentGatewayOrder = new PaymentGatewayOrder;
        $paymentGatewayOrder->user_id = auth()->user()->id;
        $paymentGatewayOrder->amount = $amount;
        $paymentGatewayOrder->status = 0; // 0 - created/ 1- success/ 2-error/ 3-pending
        $paymentGatewayOrder->type = self::TYPE_UNITPAY_NAME;
        $paymentGatewayOrder->save();

        return $paymentGatewayOrder;
    }

    public static function qiwi($amount)
    {
        $paymentGatewayOrder = new PaymentGatewayOrder;
        $paymentGatewayOrder->user_id = auth()->user()->id;
        $paymentGatewayOrder->amount = $amount;
        $paymentGatewayOrder->number = (string) Str::uuid();
        $paymentGatewayOrder->status = 0; // 0 - created/ 1- success/ 2-error/ 3-pending
        $paymentGatewayOrder->type = self::TYPE_QIWI_NAME;
        $paymentGatewayOrder->save();

        return $paymentGatewayOrder;
    }

    public static function yookassa($amount)
    {
        $paymentGatewayOrder = new PaymentGatewayOrder;
        $paymentGatewayOrder->user_id = auth()->user()->id;
        $paymentGatewayOrder->amount = $amount;
        $paymentGatewayOrder->number = (string) Str::uuid();
        $paymentGatewayOrder->status = 0; // 0 - created/ 1- success/ 2-error/ 3-pending
        $paymentGatewayOrder->type = self::TYPE_YOO_NAME;
        $paymentGatewayOrder->save();

        return $paymentGatewayOrder;
    }

}
