<?php

namespace App\Models;

use Laravel\Cashier\Subscription as CashierSubscription;

class Subscription extends CashierSubscription
{
    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        // Merged by Eloquent with Cashier's own $casts (ends_at, quantity, trial_ends_at).
        return [
            'cancel_at' => 'datetime',
        ];
    }

    /**
     * Whether Stripe will renew this subscription at the end of the current period.
     *
     * A `cancel_at` set at checkout (the user declined auto-renewal) makes Stripe
     * cancel the subscription at the 1-year mark instead of billing it again.
     */
    public function autoRenews(): bool
    {
        return is_null($this->cancel_at);
    }
}
