//
//  LoginState.swift
//  punchnet
//
//  Created by 安礼成 on 2026/1/16.
//

import Foundation
import Observation
import SwiftUI

@Observable
class RegisterModel {
    
    enum Stage: Equatable {
        case requestVerifyCode
        case submitVerifyCode
        case setPassword
        case success
    }
    
    // 保存临时变量
    var phoneNumber: String = ""
    var sessionId: Int = 0
    
    var stage: Stage = .requestVerifyCode
    var transitionEdge: Edge = .trailing // 默认从右进入

    func requestVerifyCode(phoneNumber: String) async throws -> AuthService.RegisterSession {
        return try await AuthService.requestRegisterVerifyCode(phoneNumber: phoneNumber)
    }
    
    func submitVerifyCode(sessionId: Int, verifyCode: String) async throws -> String {
        return try await AuthService.submitRegisterVerifyCode(sessionId: sessionId, verifyCode: verifyCode)
    }
    
    func register(sessionId: Int, password: String) async throws -> String {
        return try await AuthService.register(sessionId: sessionId, password: password)
    }
    
}
