// // FilterV1.swift // Pachyderm // // Created by Shadowfacts on 9/9/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import Foundation public struct FilterV1: Decodable { public let id: String public let phrase: String private let context: [String] public let expiresAt: Date? public let irreversible: Bool public let wholeWord: Bool public var contexts: [Context] { get { return context.compactMap(Context.init) } } public static func update(_ filterID: String, phrase: String, context: [Context], irreversible: Bool, wholeWord: Bool, expiresIn: TimeInterval?) -> Request { return Request(method: .put, path: "/api/v1/filters/\(filterID)", body: ParametersBody([ "phrase" => phrase, "whole_word" => wholeWord, "expires_in" => expiresIn, ] + "context" => context.contextStrings)) } public static func delete(_ filterID: String) -> Request { return Request(method: .delete, path: "/api/v1/filters/\(filterID)") } private enum CodingKeys: String, CodingKey { case id case phrase case context case expiresAt = "expires_at" case irreversible case wholeWord = "whole_word" } } extension FilterV1 { public enum Context: String, Decodable, CaseIterable { case home case notifications case `public` case thread case account } } extension Array where Element == FilterV1.Context { var contextStrings: [String] { return map { $0.rawValue } } }