//
//  WithdrawalSettingsViewModelTests.swift
//  suixinkanTests
//

import UIKit
import XCTest
@testable import suixinkan

/// 提现设置 ViewModel 测试。
final class WithdrawalSettingsViewModelTests: XCTestCase {
    func testCanGoNextStepRequiresImagesAndAgreement() {
        let viewModel = WithdrawalSettingsViewModel()
        viewModel.updateHolderName("张三")
        viewModel.updateBankNo("6222021234567890")
        viewModel.updateAgree(true)

        XCTAssertFalse(viewModel.canGoNextStep)

        try? viewModel.prepareBankCardImage(
            data: UIImage(systemName: "photo")!.pngData()!,
            side: .front
        )
        try? viewModel.prepareBankCardImage(
            data: UIImage(systemName: "photo")!.pngData()!,
            side: .back
        )

        XCTAssertTrue(viewModel.canGoNextStep)
    }

    func testCanSubmitRequiresStepTwoFields() throws {
        let viewModel = WithdrawalSettingsViewModel()
        viewModel.updateHolderName("张三")
        viewModel.updateBankNo("6222021234567890")
        viewModel.updateAgree(true)
        try viewModel.prepareBankCardImage(
            data: XCTUnwrap(UIImage(systemName: "photo")?.pngData()),
            side: .front
        )
        try viewModel.prepareBankCardImage(
            data: XCTUnwrap(UIImage(systemName: "photo")?.pngData()),
            side: .back
        )
        viewModel.goNextStep()

        viewModel.updateBankName("中国银行")
        viewModel.updateBranchName("南京支行")
        viewModel.updateVerificationCode("123456")

        XCTAssertFalse(viewModel.canSubmit)

        viewModel.selectProvince(AreasResponse(id: 1, code: "32", name: "江苏", children: []))
        viewModel.selectCity(AreasResponse(id: 2, code: "3201", name: "南京", children: []))

        XCTAssertTrue(viewModel.canSubmit)
    }
}
