<?php

namespace App\Data;

use Spatie\LaravelData\Data;

class LoginResponse extends Data
{
    public function __construct(
        public string $token,
        public string $token_type,
        public int $expires_in,
        public UserData $user,
        public array $permissions,
        public array $roles,
    ) {}

    public static function success(string $token, UserData $user, array $permissions = [], array $roles = []): self
    {
        return new self(
            token: $token,
            token_type: 'Bearer',
            expires_in: config('sanctum.expiration', 60) * 60, // Convert minutes to seconds
            user: $user,
            permissions: $permissions,
            roles: $roles,
        );
    }
}
