import Dependencies import Foundation public struct Room: Codable, Equatable, Identifiable, Sendable { public let id: UUID public let projectID: Project.ID public let name: String public let heatingLoad: Double public let coolingTotal: Double public let coolingSensible: Double? public let registerCount: Int public let rectangularSizes: [RectangularSize]? public let createdAt: Date public let updatedAt: Date public init( id: UUID, projectID: Project.ID, name: String, heatingLoad: Double, coolingTotal: Double, coolingSensible: Double? = nil, registerCount: Int = 1, rectangularSizes: [RectangularSize]? = nil, createdAt: Date, updatedAt: Date ) { self.id = id self.projectID = projectID self.name = name self.heatingLoad = heatingLoad self.coolingTotal = coolingTotal self.coolingSensible = coolingSensible self.registerCount = registerCount self.rectangularSizes = rectangularSizes self.createdAt = createdAt self.updatedAt = updatedAt } } extension Room { public struct Create: Codable, Equatable, Sendable { public let projectID: Project.ID public let name: String public let heatingLoad: Double public let coolingTotal: Double public let coolingSensible: Double? public let registerCount: Int public init( projectID: Project.ID, name: String, heatingLoad: Double, coolingTotal: Double, coolingSensible: Double? = nil, registerCount: Int = 1 ) { self.projectID = projectID self.name = name self.heatingLoad = heatingLoad self.coolingTotal = coolingTotal self.coolingSensible = coolingSensible self.registerCount = registerCount } } public struct RectangularSize: Codable, Equatable, Identifiable, Sendable { public let id: UUID public let register: Int? public let height: Int public init( id: UUID = .init(), register: Int? = nil, height: Int, ) { self.id = id self.register = register self.height = height } } public struct Update: Codable, Equatable, Sendable { public let name: String? public let heatingLoad: Double? public let coolingTotal: Double? public let coolingSensible: Double? public let registerCount: Int? public let rectangularSizes: [RectangularSize]? public init( name: String? = nil, heatingLoad: Double? = nil, coolingTotal: Double? = nil, coolingSensible: Double? = nil, registerCount: Int? = nil ) { self.name = name self.heatingLoad = heatingLoad self.coolingTotal = coolingTotal self.coolingSensible = coolingSensible self.registerCount = registerCount self.rectangularSizes = nil } public init( rectangularSizes: [RectangularSize] ) { self.name = nil self.heatingLoad = nil self.coolingTotal = nil self.coolingSensible = nil self.registerCount = nil self.rectangularSizes = rectangularSizes } } } extension Array where Element == Room { public var totalHeatingLoad: Double { reduce(into: 0) { $0 += $1.heatingLoad } } public var totalCoolingLoad: Double { reduce(into: 0) { $0 += $1.coolingTotal } } public func totalCoolingSensible(shr: Double) -> Double { reduce(into: 0) { let sensible = $1.coolingSensible ?? ($1.coolingTotal * shr) $0 += sensible } } } #if DEBUG extension Room { public static let mocks = [ Room( id: UUID(0), projectID: UUID(0), name: "Kitchen", heatingLoad: 12345, coolingTotal: 1234, registerCount: 2, createdAt: Date(), updatedAt: Date() ), Room( id: UUID(1), projectID: UUID(1), name: "Bedroom - 1", heatingLoad: 12345, coolingTotal: 1456, registerCount: 1, createdAt: Date(), updatedAt: Date() ), Room( id: UUID(2), projectID: UUID(2), name: "Family Room", heatingLoad: 12345, coolingTotal: 1673, registerCount: 3, createdAt: Date(), updatedAt: Date() ), ] public static func mock(projectID: Project.ID) -> [Self] { @Dependency(\.uuid) var uuid @Dependency(\.date.now) var now return [ .init( id: uuid(), projectID: projectID, name: "Bed-1", heatingLoad: 3913, coolingTotal: 2472, coolingSensible: nil, registerCount: 1, rectangularSizes: nil, createdAt: now, updatedAt: now ), .init( id: uuid(), projectID: projectID, name: "Entry", heatingLoad: 8284, coolingTotal: 2916, coolingSensible: nil, registerCount: 2, rectangularSizes: nil, createdAt: now, updatedAt: now ), .init( id: uuid(), projectID: projectID, name: "Family Room", heatingLoad: 9785, coolingTotal: 7446, coolingSensible: nil, registerCount: 3, rectangularSizes: nil, createdAt: now, updatedAt: now ), .init( id: uuid(), projectID: projectID, name: "Kitchen", heatingLoad: 4518, coolingTotal: 5096, coolingSensible: nil, registerCount: 2, rectangularSizes: nil, createdAt: now, updatedAt: now ), .init( id: uuid(), projectID: projectID, name: "Living Room", heatingLoad: 7553, coolingTotal: 6829, coolingSensible: nil, registerCount: 2, rectangularSizes: nil, createdAt: now, updatedAt: now ), .init( id: uuid(), projectID: projectID, name: "Master", heatingLoad: 8202, coolingTotal: 2076, coolingSensible: nil, registerCount: 2, rectangularSizes: nil, createdAt: now, updatedAt: now ), ] } } #endif