//
//  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, CaseIterable {
    
    // 配偶
    case sponse = 1
    // 父母
    case parent
    // 子女
    case child
    // 兄弟姐妹
    case brother
    
    // 随行
    case accompany
    // 国籍
    case country
    // 居住信息
    case liveInfo
    // 港澳通信证
    case hkAndMacaoPassport
    
    // 中国身份证
    case chinaIdCardInfo
    // 护照及其他旅行证件
    case passPortOrTravelInfo
    
    // 配偶信息
    case spouseInfo
    // 职业信息
    case occupationInfo
    // 学历学位信息
    case degreeInfo
    // 在港信息
    case inHongKongInfo
    // 香港身份证
    case hkIdentityCardInfo
    
    // 父亲信息
    case fatherInfo
    // 母亲信息
    case motherInfo
    // 基本信息
    case basicInfo
    // 子女信息
    case childInfo
    // 是否前次婚姻子女
    case isPreviousMarriageChild
    // 兄弟姐妹信息
    case brotherInfo
    
}

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

// 表单具体条目类型
enum YHFormDetailItemType:Int {
    
    // 是否随行至香港
    case isAccompanyToHK =  1
    // 是否与主申请人同住
    case isLiveTother
    // 国家/地区
    case nationOrArea
    // 现居住城市
    case liveCity
    // 详细地址
    case detailAddress
    // 是否办理
    case isHandleHKPassPort
    
    // 证件类别
    case certificateType
    // 证件号码
    case certificateNumber
    // 中国身份证号
    case chinaIdentityCardNumber
    // 旅行证件号码
    case traverlPassportNumber
    // 签发日期
    case certificateSignDate
    // 届满日期
    case certificateValidDate
    // 签发地
    case certificateSignPlace
    
    // 配偶姓名
    case spouseName
    // 曾用名
    case everName
    // 婚前姓氏
    case befourMarryFirstName
    // 出生日期
    case birthday
    // 出生国家/地区
    case birthNation
    // 出生城市
    case birthCity
    // 职业
    case occupation
    // 职业名称
    case occupationName
    // 是否拥有学位
    case ownDegree
    // 目前是否在港
    case isNowInHK
    // 获准逗留至
    case stayHKDate
    // 在港身份
    case roleInHK
    // 是否办理过(香港身份证)
    case isHaveHkIdentityCard
    // 香港身份证号码
    case hkIdentityCardNumber
    // 学位信息X
    case degreeDetailInfo
    
    // 父亲姓名
    case fatherName
    // 母亲姓名
    case motherName
    // 婚姻状况
    case marriageState
    // 现居住国家/地区
    case liveNationOrArea
    // 仅有两个按钮 标题数组有外部提供
    case onlyDoubleChoice
    // 主申请人和现配偶是否拥有孩子抚养权
    case ownCustody
    // 子女姓名
    case childName
    // 性别
    case gender
    // 是否为前次婚姻子女
    case isPreviousMarriageChild
    // 兄弟姐妹姓名
    case brotherName
    

}

//添加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 .passPortOrTravelInfo:
            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
        case .childInfo:
            return "子女信息".local
        case .isPreviousMarriageChild:
            return "是否前次婚姻子女".local
        case .brotherInfo:
            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 .isPreviousMarriageChild:
            return "".local
        case .accompany:
            return "".local
        case .country:
            return "".local
        case .liveInfo:
            return "".local
        case .hkAndMacaoPassport:
            return "".local
        case .chinaIdCardInfo:
            return "".local
        case .passPortOrTravelInfo:
            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
        case .childInfo:
            return "".local
        case .brotherInfo:
            return "".local
            
            
        }
    }
}

// 具体item
class YHFormDetailItem : YHFormItemProtocol {
    
    var type: YHFormDetailItemType
    // 是否是必填项
    var isNeed: Bool = true
    
    var value: String?
    var placeHolder: 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 .certificateType:
            return "证件类别".local
        // 证件号码
        case .certificateNumber:
            return "证件号码".local
            
        // 证件号码
        case .chinaIdentityCardNumber:
            return "中国身份证号".local
        // 旅行证件号码
        case .traverlPassportNumber:
            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 .childName:
            return "子女姓名".local
        case .gender:
            return "性别".local
        case .isPreviousMarriageChild:
            return "是否前次婚姻子女".local
        case .brotherName:
            return "兄弟姐妹姓名".local
        case .onlyDoubleChoice:
            return "".local
            
        }
    }
    
    func getSubTitle() -> String {
        return ""
    }
}

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

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

// MARK: - 家庭成员 YHData
class YHFamilyMemberGroupInfo: SmartCodable {
    
    var father: YHFamilyMember?
    var mother: YHFamilyMember?
    var spouse: YHFamilyMember?
    var child: [YHFamilyMember]?
    var brother: [YHFamilyMember]?

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

    required init() {
        
    }
}

enum YHFamilyMemberType: Int {
    // 与后台relation字段一致
    // 1父亲  2母亲 3配偶 4子女 5兄弟姐妹
    case none = 0
    case father = 1
    case mother = 2
    case spouse = 3
    case child = 4
    case brother = 5
}

class YHFamilyMember: SmartCodable, YHFormItemProtocol {
    
    // 是否随行
    func isFollow() -> Bool {
        return follow == 1
    }
    
    func setFollow(_ follow:Bool) {
        self.follow = (follow ? 1 : 0)
    }
    
    // 是否要办理港澳通行证
    func isNeedHandleHKPassPort() -> Bool {
        return  self.isHandled == 1
    }
    
    func setNeedHandleHKPassPort(_ need:Bool) {
        self.isHandled = (need ? 1 : 0)
    }
    
    // 是否与主申请人同住
    func isLiveTother() -> Bool {
        return self.finishFollow == 1
    }
    
    func setLiveTother(_ together:Bool) {
        self.finishFollow = (together ? 1 : 0)
    }
    
    
    var id: Int = 0
    var deceased: Int = 0
    var custody: Int = 0
    var nationality: String?
    var orderId: Int = 0
    var relation: String?
    var hasDegree: String?
    
    // mark any
    // var hasDegreeJson: [YHHasDegreeJson]?
    var hasDegreeJson: SmartAny?
    
    var follow: Int = 0
    var statement: Int = 0
    var subsetName: String?
    
    // mark any
//    var subsetNamePinyin: YHSubsetNamePinyin?
    var subsetNamePinyin: SmartAny?
    
    var usedName: String?
    var birthday: String?
    var birthPlaceAboard: Int = 0
    
    // mark any
//    var birthPlace: YHAddress?
    var birthPlace: SmartAny?
    
    var occupation: String?
    var occupationName: String?
    
    // mark any
    var operatorAme: SmartAny?
    
    // mark any
//    var childHasHkId: YHChildStepchildClass?
    var childHasHkId: SmartAny?
    
    var hkIdentityCard: String?
    var sex: Int = 0
    var married: String?
    var nows: Int = 0
    
    var address: YHAddress?
    
    // mark any
//    var childStepchild: YHChildStepchildClass?
    var childStepchild: SmartAny?
    
    // mark any
//    var childInHk: YHChildStepchildClass?
    var childInHk: SmartAny?
    
    // mark any
    var countryIdentity: SmartAny?
    
    var hkIdentity: String?
    var hkIdentityOther: String?
    var liveCountry: String?
    var isHandled: Int = 0
    var finishFollow: Int = 0
    var step: Int = 0
    var notFillNum: Int = 0
    var isLiveOverseaYear: Int = 0
    var surname: String?
    
    // mark any
//    var certificates: YHCertificates?
    var certificates: SmartAny?
    var certificatesd: 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() {
        
    }
    
    var relationType:YHFamilyMemberType {
        
        if relation == "1" {
            return .father
        } else if relation == "2" {
            return .mother
        } else if relation == "3" {
            return .spouse
        } else if relation == "4" {
            return .child
        } else if relation == "5" {
            return .brother
        }
        
        return .none
    }
    
    // YHFamilyMemberProtocol
    func getTitle() -> String {
        // 1父亲  2 母亲 3 配偶 4子女 5兄弟姐妹
        if let relation = relation {
            if relation == "1" {
                return "父亲".local
            } else if relation == "2" {
                return "母亲".local
            } else if relation == "3" {
                return "配偶".local
            } else if relation == "4" {
                return "子女".local
            } else if relation == "5" {
                return "兄弟姐妹".local
            }
        }
        return ""
    }
    
    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: - YHCertificates
class YHCertificates: SmartCodable {
    
    var cnIdentityCard: YHCNIdentityCard?
    var passport: YHCNIdentityCard?
    var hkMacaoPass: YHCNIdentityCard?

    enum CodingKeys: String, CodingKey {
        case cnIdentityCard = "cnIdentityCard"
        case passport = "passport"
        case hkMacaoPass = "hkMacaoPass"
    }
        
    required init() {
        
    }
    
    init(cnIdentityCard: YHCNIdentityCard?, passport: YHCNIdentityCard?, hkMacaoPass: YHCNIdentityCard?) {
        self.cnIdentityCard = cnIdentityCard
        self.passport = passport
        self.hkMacaoPass = hkMacaoPass
    }
}

// MARK: - YHCNIdentityCard
class YHCNIdentityCard: SmartCodable {
    
    
    
    var id: Int = 0
    var number: String?
    var issueAt: String?
    var issueDateStartAt: String?
    var issueDateEndAt: String?
    var imgFront: String?
    var imgBack: String?
    var passportType: Int = 0

    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"
    }
    
    required init() {
        
    }
    
    init(id:Int, number: String?, issueAt:String?,  issueDateStartAt: String?, imgFront: String?, imgBack: String?, passportType: Int) {
        self.id = id
        self.number = number
        self.issueAt = issueAt
        self.issueDateStartAt = issueDateStartAt
        self.imgFront = imgFront
        self.imgBack = imgBack
        self.passportType = passportType
    }
}

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

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

    required init() {
        
    }
}
