// GENERATED by `cotton-gen` from `cotton-core — vault/payload.rs` — do not edit by hand.// Run `pnpm gen:design`; `gen:design:check` guards drift in CI.//// The 10 shapes a secret's sealed bytes can take.//// Read from `crates/cotton-core/src/vault/payload.rs`, which is where a kind is// declared; a kind is NEVER declared here. The plain columns of the row —// `kind`, `name`, `site`, `username`, `service` — are what a list shows and what// search indexes, and they are deliberately NOT repeated in here: a second copy// of a name inside the sealed bytes would be a second answer to what a secret is// called, and the sealed one is the one nothing can read to check.//// The wire form is FLAT and tagged on `kind`, so `{"kind":"login",// "password":"…"}` is one object rather than a nested one. Swift's synthesized// `Codable` for an enum with associated values writes a nested shape instead,// which is why `init(from:)` and `encode(to:)` are spelled out below.//// An unset optional is ABSENT rather than null, at both ends: Swift's// synthesized coding uses `encodeIfPresent`/`decodeIfPresent` for an optional// property, and the Rust side carries `skip_serializing_if`. Two spellings of// nothing would be two payloads that are the same secret.importFoundation/// What a secret IS — the same string the row's `kind` column holds.publicenumSecretKind: String, Sendable, Equatable, CaseIterable, Codable {case login = "login"case apiKey = "api_key"case note = "note"case card = "card"case identity = "identity"case document = "document"case code = "code"case wifi = "wifi"case address = "address"case file = "file"}/// A `login` secret's payload.publicstructSecretLogin: Sendable, Equatable, Codable {/// The password itself.publicvar password: String/// Anything else worth keeping with it.publicvar notes: String?/// The otpauth secret a one-time code is generated from.publicvar totp: String?/// Other addresses it is used at, one a line.publicvar urls: String?publicinit(password: String, notes: String? = nil, totp: String? = nil, urls: String? = nil) {self.password = passwordself.notes = notesself.totp = totpself.urls = urls }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { password }}/// A `api_key` secret's payload.publicstructSecretApiKey: Sendable, Equatable, Codable {/// The key itself.publicvar key: String/// Anything else worth keeping with it.publicvar notes: String?publicinit(key: String, notes: String? = nil) {self.key = keyself.notes = notes }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { key }}/// A `note` secret's payload.publicstructSecretNote: Sendable, Equatable, Codable {/// The note, whole.publicvar body: Stringpublicinit(body: String) {self.body = body }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { body }}/// A `card` secret's payload.publicstructSecretCard: Sendable, Equatable, Codable {/// The card number.publicvar number: String/// The name on the card.publicvar holder: String?/// MM/YY, as the card prints it.publicvar expiry: String?/// The verification digits.publicvar cvv: String?/// Anything else worth keeping with it.publicvar notes: String?publicinit(number: String, holder: String? = nil, expiry: String? = nil, cvv: String? = nil, notes: String? = nil) {self.number = numberself.holder = holderself.expiry = expiryself.cvv = cvvself.notes = notes }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { number }}/// A `identity` secret's payload.publicstructSecretIdentity: Sendable, Equatable, Codable {/// The document's number.publicvar number: String/// Passport, driving licence, tax id, and so on.publicvar idType: String?/// Whose it is.publicvar holder: String?/// The date it was issued.publicvar issued: String?/// The date it runs out.publicvar expires: String?/// Who issued it.publicvar country: String?/// Anything else worth keeping with it.publicvar notes: String?publicinit(number: String, idType: String? = nil, holder: String? = nil, issued: String? = nil, expires: String? = nil, country: String? = nil, notes: String? = nil) {self.number = numberself.idType = idTypeself.holder = holderself.issued = issuedself.expires = expiresself.country = countryself.notes = notes }/// The JSON keys are the Rust declaration's own spelling.privateenumCodingKeys: String, CodingKey {case numbercase idType = "id_type"case holdercase issuedcase expirescase countrycase notes }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { number }}/// A `document` secret's payload.publicstructSecretDocument: Sendable, Equatable, Codable {/// The password that unlocks a filed document.publicvar password: Stringpublicinit(password: String) {self.password = password }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { password }}/// A `code` secret's payload.publicstructSecretCode: Sendable, Equatable, Codable {/// The otpauth address (or bare base32 secret) the one-time code is made from.publicvar secret: String/// Anything else worth keeping with it.publicvar notes: String?publicinit(secret: String, notes: String? = nil) {self.secret = secretself.notes = notes }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { secret }}/// A `wifi` secret's payload.publicstructSecretWifi: Sendable, Equatable, Codable {/// The network's password.publicvar password: String/// WPA3, WPA2, WEP or none, as the router says.publicvar security: String?/// Anything else worth keeping with it.publicvar notes: String?publicinit(password: String, security: String? = nil, notes: String? = nil) {self.password = passwordself.security = securityself.notes = notes }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { password }}/// A `address` secret's payload.publicstructSecretAddress: Sendable, Equatable, Codable {/// The postal address, as it is written on an envelope.publicvar address: String/// The name it is for.publicvar fullName: String?/// An email address that goes with it.publicvar email: String?/// A phone number that goes with it.publicvar phone: String?/// Anything else worth keeping with it.publicvar notes: String?publicinit(address: String, fullName: String? = nil, email: String? = nil, phone: String? = nil, notes: String? = nil) {self.address = addressself.fullName = fullNameself.email = emailself.phone = phoneself.notes = notes }/// The JSON keys are the Rust declaration's own spelling.privateenumCodingKeys: String, CodingKey {case addresscase fullName = "full_name"case emailcase phonecase notes }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { address }}/// A `file` secret's payload.publicstructSecretFile: Sendable, Equatable, Codable {/// The file's bytes, base64 (standard, padded).publicvar content: String/// The file's name, as it was chosen or shared.publicvar fileName: String?/// The password that opens a keystore (.jks, .p12).publicvar storePassword: String?/// The key's alias inside a keystore.publicvar keyAlias: String?/// The password of that key, when it differs from the store's.publicvar keyPassword: String?/// Anything else worth keeping with it.publicvar notes: String?publicinit(content: String, fileName: String? = nil, storePassword: String? = nil, keyAlias: String? = nil, keyPassword: String? = nil, notes: String? = nil) {self.content = contentself.fileName = fileNameself.storePassword = storePasswordself.keyAlias = keyAliasself.keyPassword = keyPasswordself.notes = notes }/// The JSON keys are the Rust declaration's own spelling.privateenumCodingKeys: String, CodingKey {case contentcase fileName = "file_name"case storePassword = "store_password"case keyAlias = "key_alias"case keyPassword = "key_password"case notes }/// The field a hint is taken from, and the one Copy copies.publicvar primaryField: String { content }}/// One secret's payload — everything the person actually has to keep.publicenumSecretPayload: Sendable, Equatable {case login(SecretLogin)case apiKey(SecretApiKey)case note(SecretNote)case card(SecretCard)case identity(SecretIdentity)case document(SecretDocument)case code(SecretCode)case wifi(SecretWifi)case address(SecretAddress)case file(SecretFile)publicvar kind: SecretKind {switchself {case .login: return .logincase .apiKey: return .apiKeycase .note: return .notecase .card: return .cardcase .identity: return .identitycase .document: return .documentcase .code: return .codecase .wifi: return .wificase .address: return .addresscase .file: return .file } }/// The VALUE of the kind's primary field: what a hint is taken from, what a/// `raw` placement writes, and what Copy copies.publicvar primaryField: String {switchself {case .login(let payload): return payload.primaryFieldcase .apiKey(let payload): return payload.primaryFieldcase .note(let payload): return payload.primaryFieldcase .card(let payload): return payload.primaryFieldcase .identity(let payload): return payload.primaryFieldcase .document(let payload): return payload.primaryFieldcase .code(let payload): return payload.primaryFieldcase .wifi(let payload): return payload.primaryFieldcase .address(let payload): return payload.primaryFieldcase .file(let payload): return payload.primaryField } }/// The last 4 characters of the primary field — what a list shows/// INSTEAD of the secret. Characters, not bytes: a value ending outside/// ASCII must not be cut through the middle of one.publicvar hint: String { SecretPayload.hint(of: primaryField) }publicstaticfunc hint(of value: String) -> String {String(value.suffix(4)) }/// The sealed bytes, once they are open.publicstaticfunc decode(_ json: Data) throws -> SecretPayload {try JSONDecoder().decode(SecretPayload.self, from: json) }/// The bytes to seal.publicfunc encoded() throws -> Data {try JSONEncoder().encode(self) }}extensionSecretPayload: Codable {privateenumTagKey: String, CodingKey {case kind }publicinit(from decoder: Decoder) throws {let tag = try decoder.container(keyedBy: TagKey.self).decode(SecretKind.self, forKey: .kind)switch tag {case .login: self = .login(trySecretLogin(from: decoder))case .apiKey: self = .apiKey(trySecretApiKey(from: decoder))case .note: self = .note(trySecretNote(from: decoder))case .card: self = .card(trySecretCard(from: decoder))case .identity: self = .identity(trySecretIdentity(from: decoder))case .document: self = .document(trySecretDocument(from: decoder))case .code: self = .code(trySecretCode(from: decoder))case .wifi: self = .wifi(trySecretWifi(from: decoder))case .address: self = .address(trySecretAddress(from: decoder))case .file: self = .file(trySecretFile(from: decoder)) } }publicfunc encode(to encoder: Encoder) throws {var tag = encoder.container(keyedBy: TagKey.self)try tag.encode(kind, forKey: .kind)switchself {case .login(let payload): try payload.encode(to: encoder)case .apiKey(let payload): try payload.encode(to: encoder)case .note(let payload): try payload.encode(to: encoder)case .card(let payload): try payload.encode(to: encoder)case .identity(let payload): try payload.encode(to: encoder)case .document(let payload): try payload.encode(to: encoder)case .code(let payload): try payload.encode(to: encoder)case .wifi(let payload): try payload.encode(to: encoder)case .address(let payload): try payload.encode(to: encoder)case .file(let payload): try payload.encode(to: encoder) } }}