//
// Copyright 2025 Circle Internet Group, Inc. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//
//  NumericPinCodeInputViewManager.swift
//  Pods
//
//  Created by evahsu on 2019/10/17.
//

import Foundation
@objc(NumericPinCodeInputViewManager)
class NumericPinCodeInputViewManager: RCTViewManager {
    override func view() -> UIView! {
        let view = NumericPinCodeInputView();
        view.bridge = self.bridge
        return view;
    }

    override static func requiresMainQueueSetup() -> Bool {
        return true
    }

    @objc public func submit(_ reactTag: NSNumber, requestId: NSNumber) {
        DispatchQueue.main.async {
            let view = self.bridge.uiManager.view(forReactTag: reactTag)
            guard let inputView = view as? NumericPinCodeInputView else {
                return
            }
            inputView.submit(requestId: Int(requestId))
        }
    }

    @objc public func submitForMultiple(_ reactTag: NSNumber, requestId: NSNumber) {
        DispatchQueue.main.async {
            let view = self.bridge.uiManager.view(forReactTag: reactTag)
            guard let inputView = view as? NumericPinCodeInputView else {
                return
            }
            inputView.submitForMultiple(requestId: Int(requestId))
        }
    }

    @objc public func submitPlain(_ reactTag: NSNumber, requestId: NSNumber) {
        DispatchQueue.main.async {
            let view = self.bridge.uiManager.view(forReactTag: reactTag)
            guard let inputView = view as? NumericPinCodeInputView else {
                return
            }
            inputView.submitPlain(requestId: Int(requestId))
        }
    }

    @objc public func getStrengthLevel(_ reactTag: NSNumber, requestId: NSNumber, checkLength: NSNumber) {
        DispatchQueue.main.async {
            let view = self.bridge.uiManager.view(forReactTag: reactTag)
            guard let inputView = view as? NumericPinCodeInputView else {
                return
            }
            inputView.getStrengthLevel(requestId: Int(requestId), checkLength: Int(checkLength))
        }
    }

    @objc public func isSamePin(_ reactTag: NSNumber, requestId: NSNumber, pinSecret1: NSDictionary, pinSecret2: NSDictionary) {
        DispatchQueue.main.async {
            let view = self.bridge.uiManager.view(forReactTag: reactTag)
            guard let inputView = view as? NumericPinCodeInputView else {
                return
            }
            inputView.isSamePin(requestId: Int(requestId), pinSecret1: pinSecret1, pinSecret2: pinSecret2)
        }
    }

    @objc public func clear(_ reactTag: NSNumber) {
        DispatchQueue.main.async {
            let view = self.bridge.uiManager.view(forReactTag: reactTag)
            guard let inputView = view as? NumericPinCodeInputView else {
                return
            }
            inputView.clear()

        }
    }
}
