1
1
package travelator.itinerary
2
2
3
3
import travelator.Id
4
- import travelator.geo.MapOverlay
4
+ import travelator.Location
5
+ import travelator.geo.*
5
6
import travelator.money.Money
7
+ import java.time.Duration
8
+ import java.time.Period
9
+ import java.time.ZonedDateTime
6
10
7
11
interface ItineraryItem {
8
12
val id: Id <ItineraryItem >
9
13
val description: String
10
14
val costs: List <Money >
11
15
val mapOverlay: MapOverlay
16
+ }
17
+
18
+ data class Accommodation (
19
+ override val id : Id <Accommodation >,
20
+ val location : Location ,
21
+ val checkInFrom : ZonedDateTime ,
22
+ val checkOutBefore : ZonedDateTime ,
23
+ val pricePerNight : Money
24
+ ) : ItineraryItem {
25
+ val nights = Period .between(checkInFrom.toLocalDate(), checkOutBefore.toLocalDate()).days
26
+ val totalPrice: Money = pricePerNight * nights
27
+
28
+ override val description
29
+ get() = " $nights nights at ${location.userReadableName} "
30
+ override val costs
31
+ get() = listOf (totalPrice)
32
+ override val mapOverlay
33
+ get() = PointOverlay (
34
+ id = id,
35
+ position = location.position,
36
+ text = location.userReadableName,
37
+ icon = StandardIcons .HOTEL
38
+ )
39
+
40
+ }
41
+
42
+ data class Attraction (
43
+ override val id : Id <Attraction >,
44
+ val location : Location ,
45
+ val notes : String
46
+ ) : ItineraryItem {
47
+ override val description get() =
48
+ location.userReadableName
49
+
50
+ override val costs get() =
51
+ emptyList<Money >()
52
+
53
+ override val mapOverlay get() =
54
+ PointOverlay (
55
+ position = location.position,
56
+ text = description,
57
+ icon = StandardIcons .ATTRACTION ,
58
+ id = id
59
+ )
60
+
61
+ }
62
+
63
+ data class Journey (
64
+ override val id : Id <Journey >,
65
+ val travelMethod : TravelMethod ,
66
+ val departsFrom : Location ,
67
+ val departureTime : ZonedDateTime ,
68
+ val arrivesAt : Location ,
69
+ val arrivalTime : ZonedDateTime ,
70
+ val price : Money ,
71
+ val path : List <Position > = listOf(departsFrom.position, arrivesAt.position),
72
+ ) : ItineraryItem {
73
+ override val description
74
+ get() = " ${departsFrom.userReadableName} " +
75
+ " to ${arrivesAt.userReadableName} " +
76
+ " by ${travelMethod.userReadableName} "
77
+
78
+ override val costs
79
+ get() = listOf (price)
80
+
81
+ override val mapOverlay
82
+ get() = OverlayGroup (
83
+ id = id,
84
+ elements = listOf (
85
+ PathOverlay (path, travelMethod.userReadableName),
86
+ PointOverlay (departsFrom.position, departsFrom.userReadableName, StandardIcons .START ),
87
+ PointOverlay (arrivesAt.position, arrivesAt.userReadableName, StandardIcons .END )
88
+ )
89
+ )
90
+
91
+ }
92
+
93
+ data class RestaurantBooking (
94
+ override val id : Id <RestaurantBooking >,
95
+ val location : Location ,
96
+ val time : ZonedDateTime
97
+ ) : ItineraryItem {
98
+ override val description get() = location.userReadableName
99
+
100
+ override val costs get() = emptyList<Money >()
101
+
102
+ override val mapOverlay get() =
103
+ PointOverlay (
104
+ id = id,
105
+ position = location.position,
106
+ text = location.userReadableName,
107
+ icon = StandardIcons .RESTAURANT
108
+ )
12
109
}
0 commit comments