import Dependencies import Foundation /// Represents a vendor item in the database. /// /// A vendor is parent item that contains one or more branches where purchase orders /// can be issued to. It is primarily a name space to group related branches together. public struct Vendor: Codable, Equatable, Identifiable, Sendable { public var id: UUID public var name: String public var branches: [VendorBranch]? public var createdAt: Date? public var updatedAt: Date? public init( id: UUID, name: String, branches: [VendorBranch]? = nil, createdAt: Date? = nil, updatedAt: Date? = nil ) { self.id = id self.name = name self.branches = branches self.createdAt = createdAt self.updatedAt = updatedAt } } public extension Vendor { /// Represents the fields required to generate a new vendor in the database. struct Create: Codable, Sendable, Equatable { public let name: String public init(name: String) { self.name = name } } /// Represents the fields required to update a vendor in the database. struct Update: Codable, Sendable, Equatable { public let name: String public init(name: String) { self.name = name } } } #if DEBUG public extension Vendor.Create { static func generateMocks(count: Int = 5) -> [Self] { (0 ... count).reduce(into: [Self]()) { array, _ in array.append(.init( name: RandomNames.companyNames.randomElement()! + String(RandomNames.characterString.randomElement()!) )) } } } #endif