//
//  HealthInsurance.swift
//  iPOS
//
//  Created by Daniel Ciuciu on 12/18/19.
//  Copyright © 2019 BBC. All rights reserved.
//

import Foundation
import ObjectMapper

class HealthInsuranceRequest: Mappable {
    var storeId: Int!
    var cashRegister: Int!
    var companyId: Int!
    var senderCompanyId: Int!
    var dateFrom: Date = Date()
    var dateTo: Date = Date()
    var loadType: String = "N"
    var action: String = "L"
    var receipts: [UUID] = []
    
    init() {
        self.storeId = Int(settings.StoreId)!
        self.cashRegister = Int(settings.CashRegister)!
        self.companyId = Int(settings.userSettings.companyId)
    }
    
    required init?(map: Map){
    }
    
    func mapping(map: Map) {
        storeId <- map["StoreId"]
        cashRegister <- map["CashRegister"]
        companyId <- map["CompanyId"]
        senderCompanyId <- map["SenderCompanyId"]
        dateFrom <- (map["DateFrom"], Util.CustomDateTransform())
        dateTo <- (map["DateTo"], Util.CustomDateTransform())
        loadType <- map["LoadType"]
        action <- map["Action"]
        receipts <- map["Receipts"]
    }
}

class HealthInsuranceResponse: Mappable {
    var receipts: [HealthInsuranceReceipt] = []
    var settings: HealthInsuranceSettings = HealthInsuranceSettings()
    var resultCode: Int = -1
    var errorMessage: String = ""
    
    init() {
        
    }
    
    required init?(map: Map){
        
    }
    
    func mapping(map: Map) {
        receipts <- map["HealthInsuranceReceipts"]
        settings <- map["Settings"]
        resultCode <- map["ResultCode"]
        errorMessage <- map["ErrorMessage"]
    }
}

class HealthInsuranceReceipt: Mappable {
    var healthInsuranceReceiptId: Int!
    var receiptId: UUID!
    var exportTime: Date!
    var protocolNumber: String!
    var issueDate: Date!
    var cashRegister: Int!
    var documentFiscalNumber: String!
    var contactFiscalCode: String!
    var amountMedicalDevice: Double!
    var amountOther: Double!
    var createTime: Date!
    var totalAmount: Double!
    var contactName: String!
    var paymentDate: Date!
    var receiptNumber: Int!
    var resultMessage: String?
    var sendStatus: Int!
    var rowType: String!
    var referenceCashRegister: Int!
    var referenceCreateTime: Date!
    var referenceReceiptFiscalNumber: String!
    var storeName: String!
    var storeCode: String!
    
    var accessoryType: UITableViewCell.AccessoryType = .none
    
    init() {
        
    }
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        healthInsuranceReceiptId <- map["HealthInsuranceReceiptId"]
        receiptId <- map["ReceiptId"]
        exportTime <- (map["ExportTime"], Util.CustomDateTransform())
        protocolNumber <- map["ProtocolNumber"]
        issueDate <- (map["IssueDate"], Util.CustomDateTransform())
        cashRegister <- map["CashRegister"]
        documentFiscalNumber <- map["DocumentFiscalNumber"]
        contactFiscalCode <- map["ContactFiscalCode"]
        amountMedicalDevice <- (map["AmountMedicalDevice"], Util.CustomDoubleTransform())
        amountOther <- (map["AmountOther"], Util.CustomDoubleTransform())
        createTime <- (map["CreateTime"], Util.CustomDateTransform())
        totalAmount <- (map["TotalAmount"], Util.CustomDoubleTransform())
        contactName <- map["ContactName"]
        paymentDate <- (map["PaymentDate"], Util.CustomDateTransform())
        receiptNumber <- map["ReceiptNumber"]
        resultMessage <- map["ResultMessage"]
        sendStatus <- map["SendStatus"]
        rowType <- map["RowType"]
        referenceCashRegister <- map["ReferenceCashRegister"]
        referenceCreateTime <- (map["ReferenceCreateTime"], Util.CustomDateTransform())
        referenceReceiptFiscalNumber <- map["ReferenceReceiptFiscalNumber"]
        storeName <- map["StoreName"]
        storeCode <- map["StoreCode"]
    }
}

class HealthInsuranceSettings: Mappable {
    var healthInsuranceSettingsId: Int!
    var companyId: Int!
    var ownerType: String!
    var environment: String!
    var regionCode: String!
    var aslCode: String!
    var ssaCode: String!
    var user: String!
    var password: String!
    var pin: String!
    var senderCompanyId: Int!
    var vatCode: String!
    var fiscalCode: String!
    
    init() {
        
    }
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        healthInsuranceSettingsId <- map["HealthInsuranceSettingsId"]
        companyId <- map["CompanyId"]
        ownerType <- map["OwnerType"]
        environment <- map["Environment"]
        regionCode <- map["RegionCode"]
        aslCode <- map["ASLCode"]
        ssaCode <- map["SSACode"]
        user <- map["User"]
        password <- map["Password"]
        pin <- map["PIN"]
        senderCompanyId <- map["SenderCompanyId"]
        vatCode <- map["VatCode"]
        fiscalCode <- map["FiscalCode"]
    }
}

class HISetSettingsRequest: Mappable {
    var storeId: Int!
    var cashRegister: Int!
    var healthInsuranceSettings: HealthInsuranceSettings = HealthInsuranceSettings()
    
    init() {
        self.storeId = Int(settings.StoreId)!
        self.cashRegister = Int(settings.CashRegister)!
    }
    
    required init?(map: Map) {
        
    }
    
    func mapping(map: Map) {
        storeId <- map["StoreId"]
        cashRegister <- map["CashRegister"]
        healthInsuranceSettings <- map["Settings"]
    }
}
