<?php

namespace TPS\Birzha\Actions;

use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use RainLab\Notify\Classes\ActionBase;
use TPS\Birzha\Models\Payment;

class MakeGiftAction extends ActionBase
{
    /**
     * Returns information about this event, including name and description.
     */
    public function actionDetails()
    {
        return [
            'name'        => 'Make gift',
            'description' => 'Make gift after user registered',
            'icon'        => 'icon-gift'
        ];
    }
    /**
     * Defines validation rules for the custom fields.
     * @return array
     */
    public function defineValidationRules()
    {
        return [
            'amount' => 'required|numeric'
        ];
    }
    /**
     * Field configuration for the action.
     */
    public function defineFormFields()
    {
        return 'fields.yaml';
    }

    public function getTitle()
    {
        return 'Make gift';
    }

    public function getActionIcon()
    {
        return 'icon-gift';
    }

    /**
     * Triggers this action.
     * @param array $params
     * @return void
     */
    public function triggerAction($params)
    {
        $newPayment = new Payment;
        $newPayment->user_id = $params['user']['id'];
        $newPayment->amount = $this->host->amount;
        $newPayment->payment_type = Payment::PAYMENT_TYPE_GIFT;
        $newPayment->save();
    }
}
