//
//  YHFamilyInitialInfo.swift
//  galaxy
//
//  Created by edy on 2024/1/23.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit
import SmartCodable

protocol YHFormItemProtocol {
    
    func getTitle() -> String
    func getSubTitle() -> String
}

// 表单标题类型
enum YHFormTitleItemType:Int {
    
    case sponse = 1
    case parent = 2
    case child = 3
    case brother  = 4
    
    case accompany = 5
    case country = 6
    case liveInfo = 7
    case hkPassport = 8
}

// 表单添加条目类型
enum YHFormAddItemType:Int {
    
    case addChild = 1
    case addBrother = 2
}

// 表单具体条目类型
enum YHFormDetailItemType:Int {
    
    case accompany =  1
    case country = 2
    case isLiveTother = 3
    case liveContry = 4
    case liveCity = 5
    case detailAddress = 6
    case hkPassport = 7
}

//添加item
class YHFormAddItem : YHFormItemProtocol
{
    var type: YHFormAddItemType
    
    init(type: YHFormAddItemType) {
        self.type = type
    }
    
    func getTitle() -> String {
        switch self.type {
        case .addChild:
            return "新增子女".local
        case .addBrother:
            return "新增兄弟姐妹".local
        }
    }
    
    func getSubTitle() -> String {
        return ""
    }
}


// 标题item
class YHFormTitleItem : YHFormItemProtocol {
    
    var type: YHFormTitleItemType

    init(type: YHFormTitleItemType) {
        self.type = type
    }
    
    func getTitle() -> String {
        switch self.type {
            case .sponse:
                return "配偶".local
            case .parent:
                return "父母".local
            case .brother:
                return "兄弟姐妹".local
            case .child:
                return "子女".local
            case .accompany:
                return "随行".local
            case .country:
                return "国籍".local
            case .liveInfo:
                return "居住信息".local
            case .hkPassport:
                return "港澳通行证".local
        }
    }
    
    func getSubTitle() -> String {
        switch self.type {
            case .sponse:
                return String(format: "(%@)", "如未婚、离婚、丧偶可不填".local)
            case .parent:
                return String(format: "(%@)", "包含已故".local)
            case .brother:
                return String(format: "(%@)", "如无可不填".local)
            case .child:
                return String(format: "(%@)", "如无可不填".local)
            case .accompany:
                return "".local
            case .country:
                return "".local
            case .liveInfo:
                return "".local
            case .hkPassport:
                return "".local
        }
    }
}

// 具体item
class YHFormDetailItem : YHFormItemProtocol {
    
    var type: YHFormDetailItemType
    // 是否是必填项
    var isNeed: Bool = true
    
    // 是否随行
    var isAccompany:Bool = false
    // 港澳通信证
    var isHongKongMacouPassport:Bool = false
    // 国籍
    var country:String? = ""
    
    /** 居住信息  **/
    // 是否与主申请人同住
    var isLiveTogether:Bool = false
    // 现居住国家
    var liveContry:String? = ""
    // 现居住城市
    var liveCity:String? = ""
    // 现居住详细地址
    var liveAddress:String? = ""
    
    init(type: YHFormDetailItemType) {
        self.type = type
    }
    
    
    func getTitle() -> String {
        
        switch type {
        case .accompany:
            return "是否随行至香港".local
        case .country:
            return String(format: "%@/%@", "国家".local, "地区".local)
        case .isLiveTother:
            return "是否与主申请人同住".local
        case .liveContry:
            return String(format: "%@/%@", "国家".local, "地区".local)
        case .liveCity:
            return String(format: "%@/%@", "国家".local, "地区".local)
        case .detailAddress:
            return "详细地址".local
        case .hkPassport:
            return "是否办理".local
        }
    }
    
    func getSubTitle() -> String {
        return ""
    }
}

/*  ***** ***** ***** ***** ***** ***** ***** ***** */
// MARK: - YHWelcome
class YHWelcome: SmartCodable {
    
    var code: Int = -1
    var msg: String = ""
    var data: YHFamilyMemberInfo?

    enum CodingKeys: String, CodingKey {
        case code = "code"
        case msg = "msg"
        case data = "data"
    }
    
    required init() {
        
    }
}

// MARK: - 家庭成员 YHData
class YHFamilyMemberInfo: SmartCodable {
    
    var father: YHParent?
    var mother: YHParent?
    var spouse: YHSpouse?
    var child: [YHChild]?
    var brother: [YHBrother]?

        enum CodingKeys: String, CodingKey {
            case father = "father"
            case mother = "mother"
            case spouse = "spouse"
            case brother = "brother"
            case child = "child"
        }

    required init() {
        
    }
}

// MARK: - 子女初始信息 YHChild
class YHChild: SmartCodable, YHFormItemProtocol {
    
    var id: Int = -1
    var deceased: Int = -1
    var custody: Int = -1
    var nationality: String?
    var orderId: Int = -1
    var relation: String?
    var hasDegree: String?
    var hasDegreeJson: [SmartAny]?
    var follow: Int = -1
    var statement: Int = -1
    var subsetName: String?
    var subsetNamePinyin: YHSubsetNamePinyin?
    var usedName: String?
    var birthday: String?
    var birthPlaceAboard: Int = -1
    var birthPlace: YHAddress?
    var occupation: String?
    var occupationName: String?
    var operatorAme: SmartAny?
    var childHasHkId: YHChildStepchildClass?
    var hkIdentityCard: String?
    var sex: Int = -1
    var married: String?
    var nows: Int = -1
    var address: YHAddress?
    var childStepchild: YHChildStepchildClass?
    var childInHk: YHChildStepchildClass?
    var countryIdentity: [SmartAny]?
    var hkIdentity: String?
    var hkIdentityOther: String?
    var liveCountry: String?
    var isHandled: Int = -1
    var finishFollow: Int = -1
    var step: Int = -1
    var notFillNum: Int = -1
    var isLiveOverseaYear: Int = -1
    var surname: String?
    var certificates: [SmartAny]?

    enum CodingKeys: String, CodingKey {
        case id = "id"
        case deceased = "deceased"
        case custody = "custody"
        case nationality = "nationality"
        case orderId = "order_id"
        case relation = "relation"
        case hasDegree = "has_degree"
        case hasDegreeJson = "has_degree_json"
        case follow = "follow"
        case statement = "statement"
        case subsetName = "subset_name"
        case subsetNamePinyin = "subset_name_pinyin"
        case usedName = "used_name"
        case birthday = "birthday"
        case birthPlaceAboard = "birth_place_aboard"
        case birthPlace = "birth_place"
        case occupation = "occupation"
        case occupationName = "occupation_name"
        case operatorAme = "operator_ame"
        case childHasHkId = "child_has_hk_id"
        case hkIdentityCard = "hk_identity_card"
        case sex = "sex"
        case married = "married"
        case nows = "nows"
        case address = "address"
        case childStepchild = "child_stepchild"
        case childInHk = "child_in_hk"
        case countryIdentity = "country_identity"
        case hkIdentity = "hk_identity"
        case hkIdentityOther = "hk_identity_other"
        case liveCountry = "live_country"
        case isHandled = "is_handled"
        case finishFollow = "finish_follow"
        case step = "step"
        case notFillNum = "not_fill_num"
        case isLiveOverseaYear = "is_live_oversea_year"
        case surname = "surname"
        case certificates = "certificates"
    }
    
    required init() {
        
    }
    
    // YHFamilyMemberProtocol
    func getTitle() -> String {
        return "配偶".local
    }
    
    func getSubTitle() -> String {
        return ""
    }
}

// MARK: - YHBrother
class YHBrother: SmartCodable, YHFormItemProtocol {
    var id: Int? = -1
    var deceased: Int? = -1
    var custody: Int? = -1
    var nationality: String?
    var orderId: Int? = -1
    var relation: String?
    var hasDegree: String?
    var hasDegreeJson: [SmartAny]?
    var follow: Int? = -1
    var statement: Int? = -1
    var subsetName: String?
    var subsetNamePinyin: YHSubsetNamePinyin?
    var usedName: String?
    var birthday: String?
    var birthPlaceAboard: Int? = -1
    var birthPlace: YHAddress?
    var occupation: String?
    var occupationName: String?
    var operatorAme: SmartAny?
    var childHasHkId: YHChildStepchildClass?
    var hkIdentityCard: String?
    var sex: Int? = -1
    var married: String?
    var nows: Int? = -1
    var address: YHAddress?
    var childStepchild: YHChildStepchildClass?
    var childInHk: YHChildStepchildClass?
    var countryIdentity: [SmartAny]?
    var hkIdentity: String?
    var hkIdentityOther: String?
    var liveCountry: String?
    var isHandled: Int? = -1
    var finishFollow: Int? = -1
    var step: Int? = -1
    var notFillNum: Int? = -1
    var isLiveOverseaYear: Int? = -1
    var surname: String?
    var certificates: [SmartAny]?
    
    enum CodingKeys: String, CodingKey {
        case id = "id"
        case deceased = "deceased"
        case custody = "custody"
        case nationality = "nationality"
        case orderId = "order_id"
        case relation = "relation"
        case hasDegree = "has_degree"
        case hasDegreeJson = "has_degree_json"
        case follow = "follow"
        case statement = "statement"
        case subsetName = "subset_name"
        case subsetNamePinyin = "subset_name_pinyin"
        case usedName = "used_name"
        case birthday = "birthday"
        case birthPlaceAboard = "birth_place_aboard"
        case birthPlace = "birth_place"
        case occupation = "occupation"
        case occupationName = "occupation_name"
        case operatorAme = "operator_ame"
        case childHasHkId = "child_has_hk_id"
        case hkIdentityCard = "hk_identity_card"
        case sex = "sex"
        case married = "married"
        case nows = "nows"
        case address = "address"
        case childStepchild = "child_stepchild"
        case childInHk = "child_in_hk"
        case countryIdentity = "country_identity"
        case hkIdentity = "hk_identity"
        case hkIdentityOther = "hk_identity_other"
        case liveCountry = "live_country"
        case isHandled = "is_handled"
        case finishFollow = "finish_follow"
        case step = "step"
        case notFillNum = "not_fill_num"
        case isLiveOverseaYear = "is_live_oversea_year"
        case surname = "surname"
        case certificates = "certificates"
    }
    
    required init() {
        
    }
    
    // YHFamilyMemberProtocol
    func getTitle() -> String {
        return "兄弟姐妹".local
    }
    
    func getSubTitle() -> String {
        return ""
    }
}

// MARK: - 居住地址信息 YHAddress
class YHAddress: SmartCodable {
    var area: [String]?
    var country: String?
    var details: String?
    var foreign: String?

    enum CodingKeys: String, CodingKey {
        case area = "area"
        case country = "country"
        case details = "details"
        case foreign = "foreign"
    }

    required init() {
        
    }
}

// MARK: - YHChildStepchildClass
class YHChildStepchildClass: SmartCodable {
    var has: String?
    var info: String?

    enum CodingKeys: String, CodingKey {
        case has = "has"
        case info = "info"
    }

    required init() {
        
    }
}

// MARK: - YHSubsetNamePinyin
class YHSubsetNamePinyin: SmartCodable {
    var familyName: String?
    var givenName: String?

    enum CodingKeys: String, CodingKey {
        case familyName = "family_name"
        case givenName = "given_name"
    }

    required init() {
        
    }
}

// MARK: - 父母信息 YHParent
class YHParent: SmartCodable, YHFormItemProtocol {
    var id: Int = -1
    var deceased: Int = -1
    var custody: Int = -1
    var nationality: String?
    var orderId: Int = -1
    var relation: Int = -1
    var hasDegree: Int = -1
    var hasDegreeJson: [SmartAny]?
    var follow: Int = -1
    var statement: Int = -1
    var subsetName: String?
    var subsetNamePinyin: String?
    var usedName: String?
    var birthday: String?
    var birthPlaceAboard: Int = -1
    var birthPlace: [SmartAny]?
    var occupation: String?
    var occupationName: String?
    var operatorAme: String?
    var childHasHkId: [SmartAny]?
    var hkIdentityCard: String?
    var sex: Int = -1
    var married: Int = -1
    var nows: Int = -1
    var address: [SmartAny]?
    var childStepchild: [SmartAny]?
    var childInHk: [SmartAny]?
    var countryIdentity: [SmartAny]?
    var hkIdentity: String?
    var hkIdentityOther: String?
    var liveCountry: String?
    var isHandled: Int = -1
    var finishFollow: Int = -1
    var step: Int = -1
    var notFillNum: Int = -1
    var certificates: [SmartAny]?
    var isLiveOverseaYear: Int = -1

    enum CodingKeys: String, CodingKey {
        case id = "id"
        case deceased = "deceased"
        case custody = "custody"
        case nationality = "nationality"
        case orderId = "order_id"
        case relation = "relation"
        case hasDegree = "has_degree"
        case hasDegreeJson = "has_degree_json"
        case follow = "follow"
        case statement = "statement"
        case subsetName = "subset_name"
        case subsetNamePinyin = "subset_name_pinyin"
        case usedName = "used_name"
        case birthday = "birthday"
        case birthPlaceAboard = "birth_place_aboard"
        case birthPlace = "birth_place"
        case occupation = "occupation"
        case occupationName = "occupation_name"
        case operatorAme = "operator_ame"
        case childHasHkId = "child_has_hk_id"
        case hkIdentityCard = "hk_identity_card"
        case sex = "sex"
        case married = "married"
        case nows = "nows"
        case address = "address"
        case childStepchild = "child_stepchild"
        case childInHk = "child_in_hk"
        case countryIdentity = "country_identity"
        case hkIdentity = "hk_identity"
        case hkIdentityOther = "hk_identity_other"
        case liveCountry = "live_country"
        case isHandled = "is_handled"
        case finishFollow = "finish_follow"
        case step = "step"
        case notFillNum = "not_fill_num"
        case certificates = "certificates"
        case isLiveOverseaYear = "is_live_oversea_year"
    }

    required init() {
        
    }
    
    // YHFamilyMemberProtocol
    func getTitle() -> String {
        if sex == 0 {
            return "父亲".local
        }
        return "母亲".local
    }
    
    func getSubTitle() -> String {
        return ""
    }
}

// MARK: - 配偶 YHSpouse
class YHSpouse: SmartCodable, YHFormItemProtocol {
    var id: Int = -1
    var deceased: Int = -1
    var custody: Int = -1
    var nationality: String?
    var orderId: Int = -1
    var relation: String?
    var hasDegree: String?
    var hasDegreeJson: [YHHasDegreeJson]?
    var follow: Int = -1
    var statement: Int = -1
    var subsetName: String?
    var subsetNamePinyin: YHSubsetNamePinyin?
    var usedName: String?
    var birthday: String?
    var birthPlaceAboard: Int = -1
    var birthPlace: YHAddress?
    var occupation: String?
    var occupationName: String?
    var operatorAme: SmartAny?
    var childHasHkId: YHPurpleChild?
    var hkIdentityCard: String?
    var sex: Int = -1
    var married: String?
    var nows: Int = -1
    var address: YHAddress?
    var childStepchild: YHChildStepchildClass?
    var childInHk: YHPurpleChild?
    var countryIdentity: [SmartAny]?
    var hkIdentity: String?
    var hkIdentityOther: String?
    var liveCountry: String?
    var isHandled: Int = -1
    var finishFollow: Int = -1
    var step: Int = -1
    var notFillNum: Int = -1
    var isLiveOverseaYear: Int = -1
    var surname: String?
    var certificates: YHCertificates?

    enum CodingKeys: String, CodingKey {
        case id = "id"
        case deceased = "deceased"
        case custody = "custody"
        case nationality = "nationality"
        case orderId = "order_id"
        case relation = "relation"
        case hasDegree = "has_degree"
        case hasDegreeJson = "has_degree_json"
        case follow = "follow"
        case statement = "statement"
        case subsetName = "subset_name"
        case subsetNamePinyin = "subset_name_pinyin"
        case usedName = "used_name"
        case birthday = "birthday"
        case birthPlaceAboard = "birth_place_aboard"
        case birthPlace = "birth_place"
        case occupation = "occupation"
        case occupationName = "occupation_name"
        case operatorAme = "operator_ame"
        case childHasHkId = "child_has_hk_id"
        case hkIdentityCard = "hk_identity_card"
        case sex = "sex"
        case married = "married"
        case nows = "nows"
        case address = "address"
        case childStepchild = "child_stepchild"
        case childInHk = "child_in_hk"
        case countryIdentity = "country_identity"
        case hkIdentity = "hk_identity"
        case hkIdentityOther = "hk_identity_other"
        case liveCountry = "live_country"
        case isHandled = "is_handled"
        case finishFollow = "finish_follow"
        case step = "step"
        case notFillNum = "not_fill_num"
        case isLiveOverseaYear = "is_live_oversea_year"
        case surname = "surname"
        case certificates = "certificates"
    }
    
    required init() {
        
    }
    
    // YHFamilyMemberProtocol
    func getTitle() -> String {
        return "配偶".local
    }
    
    func getSubTitle() -> String {
        return ""
    }
}

// MARK: - YHCertificates
class YHCertificates: SmartCodable {
    
    required init() {
        
    }
    var cnIdentityCard: YHCNIdentityCard?
    var passport: YHCNIdentityCard?

    enum CodingKeys: String, CodingKey {
        case cnIdentityCard = "cnIdentityCard"
        case passport = "passport"
    }
}

// MARK: - YHCNIdentityCard
class YHCNIdentityCard: SmartCodable {
    
    required init() {
        
    }
    
    var id: Int = -1
    var number: String?
    var issueAt: String?
    var issueDateStartAt: String?
    var issueDateEndAt: String?
    var imgFront: String?
    var imgBack: String?
    var passportType: Int = -1

    enum CodingKeys: String, CodingKey {
        case id = "id"
        case number = "number"
        case issueAt = "issue_at"
        case issueDateStartAt = "issue_date_start_at"
        case issueDateEndAt = "issue_date_end_at"
        case imgFront = "img_front"
        case imgBack = "img_back"
        case passportType = "passport_type"
    }
}

// MARK: - YHPurpleChild
class YHPurpleChild: SmartCodable {
    
    required init() {
        
    }
    
    var has: String?

    enum CodingKeys: String, CodingKey {
        case has = "has"
    }
}

// MARK: - YHHasDegreeJson
class YHHasDegreeJson: SmartCodable {
    
    
    var degree: String?
    var address: String?

    enum CodingKeys: String, CodingKey {
        case degree = "degree"
        case address = "address"
    }

    required init() {
        
    }
}
