<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * Платёж SaaS (schema.sql table saas_transactions). RLS tenant_isolation.
 * status ∈ {pending, success, failed, refunded}; type ∈ {topup, refund, manual_credit, manual_debit}.
 *
 * @mixin IdeHelperSaasTransaction
 */
class SaasTransaction extends Model
{
    public const CREATED_AT = 'created_at';

    public const UPDATED_AT = null;

    public const STATUS_PENDING = 'pending';

    public const STATUS_SUCCESS = 'success';

    public const STATUS_FAILED = 'failed';

    public const TYPE_TOPUP = 'topup';

    protected $fillable = [
        'tenant_id', 'type', 'amount_rub', 'balance_rub_after', 'leads_credited',
        'gateway_id', 'gateway_code', 'gateway_payment_id', 'gateway_idempotence_key',
        'payment_method', 'legal_entity_id', 'invoice_id', 'upd_id', 'status',
        'description', 'failure_reason', 'balance_transaction_id', 'created_at', 'completed_at',
    ];

    protected function casts(): array
    {
        return [
            'amount_rub' => 'decimal:2',
            'balance_rub_after' => 'decimal:2',
            'created_at' => 'datetime',
            'completed_at' => 'datetime',
        ];
    }
}
