import type { Contract } from './Contract' type BookingType = | 'Bookings::Admin' | 'Bookings::Calendar' | 'Bookings::Clientoption' | 'Bookings::Contract' | 'Bookings::External' | 'Bookings::Owner' | 'Bookings::Salesoption' type BookingRelationshipsBookerType = | 'admin' | 'calendar' | 'clientoption' | 'contract' | 'external' | 'owner' | 'salesoption' type BookingAttributes = { checkInDate: string checkOutDate: string checkInTime: number checkOutTime: number type: BookingType } type BookingOwnerAttributes = Omit & { houseId: number owner: { id: string type: 'user' attributes: { firstName: string lastName: string } } } type BookingRelationships = { booker: { data: { id: string type: BookingRelationshipsBookerType } } comment: { data: { id: string; type: 'comment' } } } type BookingRelationshipsSerialized = { bookerId: string commentId: string } type BookingRelationshipsType = 'booker' | 'comment' type BookingRelationshipsOptions = keyof BookingRelationships type BookingOptions = { ownerBooking?: boolean relationshipOptions?: BookingRelationshipsOptions serialized?: boolean withRelationships?: boolean } type BookingAttributeCondition = Options['ownerBooking'] extends true ? BookingOwnerAttributes : BookingAttributes type BookingFieldsOmitCondition = Options['withRelationships'] extends false ? 'relationships' : '' type BookingSerialize = Pick< BookingFields, BookingCondition > & BookingAttributeCondition type BookingFieldsPickCondition = Options['serialized'] extends true ? BookingSerialize : Pick, BookingCondition> type BookingRelationshipsCondition = Options['relationshipOptions'] extends keyof BookingRelationships ? Options['relationshipOptions'] : BookingRelationshipsType type BookingCondition = Options['serialized'] extends true ? keyof Pick, 'id' | 'relationships'> : keyof BookingFields type BookingFields = { id: string type: Options['ownerBooking'] extends true ? 'bookingOwner' : 'booking' attributes: BookingAttributeCondition relationships: Options['serialized'] extends true ? BookingRelationshipsSerialized : Pick> } export type Booking< Options extends BookingOptions = { ownerBooking: false serialized: false withRelationships: true }, > = Omit< BookingFieldsPickCondition, BookingFieldsOmitCondition > // INCLUDED TYPES type BookingIncludedOptions = { includedType: 'contracts' | 'comments' serialized?: boolean fields?: string } type BookingIncludedContractCondition = Options['fields'] extends keyof Contract['attributes'] ? Contract<{ attributeOptions: Options['fields'] }>['attributes'] : Contract['attributes'] type BookingIncludedAttributesCondition< Options extends BookingIncludedOptions, > = Options['includedType'] extends 'contracts' ? BookingIncludedContractCondition : { content: string } type BookingIncludedFields = { id: string type: 'contract' | 'comment' attributes: BookingIncludedAttributesCondition relationships: Record } export type BookingIncluded< Options extends BookingIncludedOptions = { serialized: false includedType: 'contracts' fields: 'all' }, > = Options['serialized'] extends true ? Record< Options['includedType'], Pick, 'id'> & BookingIncludedAttributesCondition > : BookingIncludedFields