Untitled

 avatar
unknown
plain_text
3 years ago
5.5 kB
4
Indexable
//
//  SelfInspectionObserver.swift
//  Garageworks-iOS-Revamp
//
//  Created by mac on 14/12/22.
//

import Foundation
class SelfInspectionObserver: BaseObservableObject {
    
    @Published var sessionIdResponse: SessionIdResponse? = nil
    @Published var selfInspectionServiceQuestions: SelfInspectionServiceQuestions? = nil
    @Published var selfInspectionServiceAnswers: SelfInspectionServiceAnswers? = nil
    @Published var selfInspectionCashback: SelfInspectionCashback? = nil
    @Published var showProgress: Bool = false
    @Published var storeQuestions = ""
    // MARK: getSessionId fun Call
    func getSessionId(customer_id: String, booking_id: String){
        if !Connectivity.isConnectedToInternet() {
            return;
        }
        // MARK: Network Call
        let data = ["customer_id": customer_id, "booking_id": booking_id]
        self.showProgress = true
        NetworkManager(data: data, url: nil, service: .get_session_id, method: .post, isJSONRequest: false).executeQuery() {
            (result: Result<BaseResponse<SessionIdResponse>,Error>) in
            switch result {
            case .success(let response):
                if response.status {
                    self.sessionIdResponse = response.result.data
                    //self.getSaveSelfinspectionQuestionAnswers(booking_id: booking_id, session_id: self.sessionIdResponse?.session_id ?? "",
                      //                                                          answer_id: "1",question_id: "1", customer_id: customer_id)
                }
                print(response)
//                print(data)
            case .failure(let error):
                print(error)
            }
        }
        self.showProgress = false
    }
    // MARK: getSelfinspectionServiceQuestions fun Call
    func getSelfinspectionServiceQuestions(parent_id: String, answer_id: String, service_id: String, offset: String){
        if !Connectivity.isConnectedToInternet() {
            return;
        }
        let data = ["parent_id": parent_id, "answer_id": answer_id, "service_id": service_id, "offset": offset]
        self.showProgress = true
        NetworkManager(data: data, url: nil, service: .get_selfinspection_service_questions, method: .post, isJSONRequest: false).executeQuery() {
            (result: Result<BaseResponse<SelfInspectionServiceQuestions>,Error>) in
            switch result {
            case .success(let response):
                if response.status {
                    self.selfInspectionServiceQuestions = response.result.data
                    self.storeQuestions  = response.result.data.question ?? ""
                    print(self.storeQuestions,"Questions********")
                }
                print(response)
//                print(data)
            case .failure(let error):
                print(error)
            }
        }
        self.showProgress = false
    }
    
    // MARK: getSaveSelfinspectionQuestionAnswers fun Call
    func getSaveSelfinspectionQuestionAnswers(booking_id: String, session_id: String,
                                              answer_id: String, question_id: String ,
                                              customer_id: String){
        if !Connectivity.isConnectedToInternet() {
            return;
        }
        // MARK: Network Call
        let ques_ans: [String: Any] = [
            "answer_id": answer_id,
            "question_id": question_id
        ]
        let jsonData = try? JSONSerialization.data(withJSONObject: ques_ans, options: [])
        var jsonString = String(data: jsonData!, encoding: String.Encoding.ascii)!
        print (jsonString)
        let data = ["booking_id": booking_id, "session_id": session_id, "question_answer": jsonString, "customer_id": customer_id] as [String : Any]
        
        self.showProgress = true
        NetworkManager(data: data, url: nil, service: .save_selfinspection_question_answers, method: .post, isJSONRequest: false).executeQuery() {
            (result: Result<BaseResponse<SelfInspectionServiceAnswers>,Error>) in
            switch result {
            case .success(let response):
                if response.status {
                    self.selfInspectionServiceAnswers = response.result.data
                }
                print(response)
//                print(data)
            case .failure(let error):
                print(error)
            }
        }
        self.showProgress = false
    }
    
    // MARK: getSelfInspectionCashbackAdd fun Call
    func getSelfInspectionCashbackAdd(customer_id: String, session_id: String, booking_id: String, source: String){
        if !Connectivity.isConnectedToInternet() {
            return;
        }
        let data = ["customer_id": customer_id, "session_id": session_id, "booking_id": booking_id, "source": source]
        self.showProgress = true
        NetworkManager(data: data, url: nil, service: .self_inspection_cashback_add, method: .post, isJSONRequest: false).executeQuery() {
            (result: Result<BaseResponse<SelfInspectionCashback>,Error>) in
            switch result {
            case .success(let response):
                if response.status {
                    self.selfInspectionCashback = response.result.data
                }
                print(response)
//                print(data)
            case .failure(let error):
                print(error)
            }
        }
        self.showProgress = false
    }
}

Editor is loading...