//
//  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 hkAndMacaoPassport = 8
    
    // 中国身份证
    case chinaIdCardInfo = 9
    // 护照
    case passPortInfo = 10
    
    // 配偶信息
    case spouseInfo = 11
    // 职业信息
    case occupationInfo = 12
    // 学历学位信息
    case degreeInfo = 13
    // 在港信息
    case inHongKongInfo = 14
    // 香港身份证
    case hkIdentityCardInfo = 15
    
    // 父亲信息
    case fatherInfo = 16
    // 母亲信息
    case motherInfo = 17
    // 基本信息
    case basicInfo = 18
    
}

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

// 表单具体条目类型
enum YHFormDetailItemType:Int {
    
    // 是否随行至香港
    case isAccompanyToHK =  1
    // 是否与主申请人同住
    case isLiveTother = 3
    // 国家/地区
    case nationOrArea = 4
    // 现居住城市
    case liveCity = 5
    // 详细地址
    case detailAddress = 6
    // 是否办理
    case isHandleHKPassPort = 7
    
    // 证件类别
    case cetificateType = 8
    // 证件号码
    case certificateNumber = 9
    // 签发日期
    case certificateSignDate = 10
    // 届满日期
    case certificateValidDate = 11
    // 签发地
    case certificateSignPlace = 12
    
    // 配偶姓名
    case spouseName = 13
    // 曾用名
    case everName = 14
    // 婚前姓氏
    case befourMarryFirstName = 15
    // 出生日期
    case birthday = 16
    // 出生国家/地区
    case birthNation = 17
    // 出生城市
    case birthCity = 18
    // 职业
    case occupation = 19
    // 职业名称
    case occupationName = 20
    // 是否拥有学位
    case ownDegree = 21
    // 目前是否在港
    case isNowInHK = 22
    // 获准逗留至
    case stayHKDate = 23
    // 在港身份
    case roleInHK = 24
    // 是否办理过(香港身份证)
    case isHaveHkIdentityCard = 25
    // 香港身份证号码
    case hkIdentityCardNumber = 26
    // 学位信息X
    case degreeDetailInfo = 27
    
    // 父亲姓名
    case fatherName = 28
    // 母亲姓名
    case motherName = 29
    // 婚姻状况
    case marriageState = 30
    // 现居住国家/地区
    case liveNationOrArea = 31
    // 仅有两个按钮 标题数组有外部提供
    case onlyDoubleChoice = 32
    // 主申请人和现配偶是否拥有孩子抚养权
    case ownCustody = 33

}

//添加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
        case .addDegree:
            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 .hkAndMacaoPassport:
                return "港澳通行证".local
            case .chinaIdCardInfo:
                return "中国身份证".local
            case .passPortInfo:
                return String(format: "%@(%@)", "护照及其他旅行证件".local, "选填".local)
            case .spouseInfo:
                return "配偶信息".local
            case .occupationInfo:
                return "职业信息".local
            case .degreeInfo:
                return "学历学位信息".local
            case .inHongKongInfo:
                return "在港信息".local
            case .hkIdentityCardInfo:
                return "香港身份证".local
            case .fatherInfo:
                return "父亲信息".local
            case .motherInfo:
                return "母亲信息".local
            case .basicInfo:
                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 .hkAndMacaoPassport:
                return "".local
            case .chinaIdCardInfo:
                return "".local
            case .passPortInfo:
                return "".local
            case .spouseInfo:
                return "".local
            case .occupationInfo:
                return "".local
            case .degreeInfo:
                return "".local
            case .inHongKongInfo:
                return "".local
            case .hkIdentityCardInfo:
                return "".local
            case .fatherInfo:
                return "".local
            case .motherInfo:
                return "".local
            case .basicInfo:
                return "".local
            
        }
    }
}

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

            // 签发日期
            case .certificateSignDate:
                return "签发日期".local
            // 届满日期
            case .certificateValidDate:
                return "届满日期".local
            case .certificateSignPlace:
                return "签发地".local
            // 配偶姓名
            case .spouseName:
                return "配偶姓名".local
                // 曾用名
            case .everName:
                return "曾用名".local
                // 婚前姓氏
            case .befourMarryFirstName:
                return "婚前姓氏".local
                // 出生日期
            case .birthday:
                return "出生日期".local
                // 出生国家/地区
            case .birthNation:
                return "出生国家/地区".local
                // 出生城市
            case .birthCity:
                return "出生城市".local
                // 职业
            case .occupation:
                return "职业".local
                // 职业名称
            case .occupationName:
                return "职业名称".local
                // 是否拥有学位
            case .ownDegree:
                return "是否拥有学位".local
                // 目前是否在港
            case .isNowInHK:
                return "目前是否在港".local
                // 获准逗留至
            case .stayHKDate:
                return "获准逗留至".local
                // 在港身份
            case .roleInHK:
                return "在港身份".local
                // 是否办理过(香港身份证)
            case .isHaveHkIdentityCard:
                return "是否办理过".local
                // 香港身份证号码
            case .hkIdentityCardNumber:
                return "香港身份证号码".local
            case .degreeDetailInfo:
                return "学位信息X".local
            case .fatherName:
                return "父亲姓名".local
            case .motherName:
                return "母亲姓名".local
            case .marriageState:
                return "婚姻状况".local
            case .liveNationOrArea:
                return "现居住国家/地区".local
            case .ownCustody:
                return "主申请人和现配偶是否拥有孩子抚养权".local
            case .onlyDoubleChoice:
                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() {
        
    }
}
