//
//  PermissionApplyModels.swift
//  suixinkan
//

import Foundation

struct RoleApplyPendingResponse: Decodable, Equatable {
    let code: String
    let roleId: Int
    let roleName: String
    let scenicList: [RoleApplyScenicItem]
    let status: Int
    let statusLabel: String
    let createdAt: String
    let auditNote: String
    let auditedAt: String?
    let auditedBy: String?

    enum CodingKeys: String, CodingKey {
        case code
        case roleId = "role_id"
        case roleName = "role_name"
        case scenicList = "scenic_list"
        case status
        case statusLabel = "status_label"
        case createdAt = "created_at"
        case auditNote = "audit_note"
        case auditedAt = "audited_at"
        case auditedBy = "audited_by"
    }

    init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        code = try container.decodeIfPresent(String.self, forKey: .code) ?? ""
        roleId = try container.decodeIfPresent(Int.self, forKey: .roleId) ?? 0
        roleName = try container.decodeIfPresent(String.self, forKey: .roleName) ?? ""
        scenicList = try container.decodeIfPresent([RoleApplyScenicItem].self, forKey: .scenicList) ?? []
        status = try container.decodeIfPresent(Int.self, forKey: .status) ?? 0
        statusLabel = try container.decodeIfPresent(String.self, forKey: .statusLabel) ?? ""
        createdAt = try container.decodeIfPresent(String.self, forKey: .createdAt) ?? ""
        auditNote = try container.decodeIfPresent(String.self, forKey: .auditNote) ?? ""
        auditedAt = try container.decodeIfPresent(String.self, forKey: .auditedAt)
        auditedBy = try container.decodeIfPresent(String.self, forKey: .auditedBy)
    }
}

struct RoleApplyScenicItem: Decodable, Equatable {
    let id: Int
    let name: String
}

struct ScenicListAllResponse: Decodable, Equatable {
    let total: Int
    let list: [ScenicListItem]

    init(total: Int = 0, list: [ScenicListItem] = []) {
        self.total = total
        self.list = list
    }
}

struct ScenicListItem: Decodable, Equatable {
    let id: Int
    let name: String
}

struct RoleApplySubmitRequest: Encodable {
    let scenicId: [Int]
    let roleId: Int

    enum CodingKeys: String, CodingKey {
        case scenicId = "scenic_id"
        case roleId = "role_id"
    }
}

struct RoleOption: Equatable, Hashable {
    let id: Int
    let name: String
    let description: String
    var isSelected: Bool
}

struct ScenicOption: Equatable, Hashable {
    let id: Int
    let name: String
    var isSelected: Bool
    var isDisabled: Bool
}

struct RoleApplySubmitResult: Decodable, Equatable {
    let code: String

    init(code: String = "") {
        self.code = code
    }

    init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        code = try container.decodeIfPresent(String.self, forKey: .code) ?? ""
    }

    private enum CodingKeys: String, CodingKey {
        case code
    }
}
