//
//  UserValidationResponse.swift
//  iPOS
//
//  Created by bbc on 24/08/2017.
//  Copyright © 2017 BBC. All rights reserved.
//

import Foundation
import ObjectMapper

class  UserValidationResponse: Mappable{
    var message: String = ""
    var storeId: Int = -1
    var storeCode: String = ""
    var userId: UUID?
    var userCode: Int?
    var userName: String?
    var isUsernameOrPasswordInvalid = true
    var isUsernameDisabled = true
    var isAdministrative: Bool = false
    var changePasswordOnFirstLogon: Bool = false
    var isFreeVersion: Bool = true
    var licenseMessage: String = ""
    var currencyId: String = ""
    var userPermissions: [String] = []
    var userRoles: [String] = []
    
    var countryId: Int = -1
    var countryCode: String = ""
    
    var companyId: Int = -1
    var companyCode: String = ""
    var companyName: String = ""
    var twoLettersISOCultureCode: String = ""
    
    var storeSetup: StoreSetup_Result?
    
    var defaultCurrency: String{
        get{
            return Util.decodeCurrencyId(currencyId: self.currencyId)
        }
    }
    
    init() {
        
    }
    
    required init?(map: Map){
        
    }
    
    func mapping(map: Map) {
        message <- map["Message"]
        storeId <- map["StoreId"]
        userId <- (map["UserId"], Util.CustomUuidTransform())
        userName <- map["UserName"]
        isUsernameOrPasswordInvalid <- map["IsUsernameOrPasswordInvalid"]
        isUsernameDisabled <- map["IsUsernameDisabled"]
        isFreeVersion <- map["IsFreeVersion"]
        licenseMessage <- map["LicenseErrorMessage"]
        currencyId <- map["CurrencyId"]
        isAdministrative <- map["IsAdministrative"]
        changePasswordOnFirstLogon <- map["ChangePasswordOnFirstLogon"]
        storeCode <- map["StoreCode"]
        userCode <- map["UserCode"]
        
        countryId <- map["CountryId"]
        countryCode <- map["CountryCode"]
        
        companyId <- map["CompanyId"]
        companyCode <- map["CompanyCode"]
        companyName <- map["CompanyName"]
        twoLettersISOCultureCode <- map["TwoLettersISOCultureCode"]
        
        storeSetup <- map["StoreSetup_Result"]
        var userPermissionsString: String?
        userPermissionsString <- map["UserPermissionsString"]
        if let permissionsString = userPermissionsString {
                userPermissions = permissionsString.components(separatedBy: ",")
               }
               
        var userRolesString: String?
        userRolesString <- map["UserRolesString"]
        if let rolesString = userRolesString {
            userRoles = rolesString.components(separatedBy: ",")
        }
    }
}
