<?php

declare(strict_types=1);

namespace App\Models;

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

class WorkspaceSubscription extends Model
{
    use HasFactory;

    public const STATE_TRIAL = 'trial';

    public const STATE_ACTIVE = 'active';

    public const STATE_PAST_DUE = 'past_due';

    public const STATE_CANCEL_AT_PERIOD_END = 'cancel_at_period_end';

    public const STATE_ENDED = 'ended';

    protected $guarded = [];

    /**
     * @return list<string>
     */
    public static function stateIds(): array
    {
        return [
            self::STATE_TRIAL,
            self::STATE_ACTIVE,
            self::STATE_PAST_DUE,
            self::STATE_CANCEL_AT_PERIOD_END,
            self::STATE_ENDED,
        ];
    }

    protected function casts(): array
    {
        return [
            'trial_ends_at' => 'datetime',
            'current_period_starts_at' => 'datetime',
            'current_period_ends_at' => 'datetime',
        ];
    }

    /**
     * @return BelongsTo<Workspace, $this>
     */
    public function workspace(): BelongsTo
    {
        return $this->belongsTo(Workspace::class);
    }
}