package pl.firmatpp.kierowca.data.model

data class RequestOtpBody(val phoneNumber: String)

data class VerifyOtpBody(
    val phoneNumber: String,
    val code: String,
    val deviceName: String,
    val device: DriverDeviceInfo,
)

data class DriverDeviceInfo(
    val deviceId: String,
    val androidId: String?,
    val brand: String?,
    val manufacturer: String?,
    val model: String?,
    val device: String?,
    val product: String?,
    val androidVersion: String?,
    val sdkInt: Int,
    val appVersion: String?,
    val serialNumber: String?,
)

data class OtpResponse(
    val ok: Boolean,
    val phoneMasked: String?,
    val expiresInSeconds: Int?,
)

data class VerifyOtpResponse(
    val ok: Boolean,
    val accessToken: String?,
    val expiresAt: String?,
    val driver: DriverDto?,
)

data class DriverDto(
    val id: String,
    val displayName: String,
    val anonymousLabel: String?,
)

data class BootstrapResponse(
    val session: DriverSessionDto,
    val routes: RoutesBucketDto,
    val driverAppSettings: DriverAppSettingsDto?,
    val dispatchSheetReminder: DispatchSheetReminderDto? = null,
    val notificationPreferences: NotificationPreferencesDto? = null,
    val realtime: RealtimeConfigDto? = null,
    val syncState: SyncStateResponse? = null,
)

data class DriverAppSettingsDto(
    val minDate: String,
    val maxDate: String,
    val today: String,
    val selectedDate: String,
    val maxPastDays: Int,
    val autoRefreshSeconds: Int,
    val allowGalleryUploads: Boolean?,
    val allowRouteCompletion: Boolean?,
    val requirePreciseLocationForPhotos: Boolean?,
    val dispatchSheetRemindersEnabled: Boolean? = null,
    val dispatchSheetOnFridays: Boolean? = null,
    val dispatchSheetOnLastWorkingDay: Boolean? = null,
    val leaveRequests: LeaveRequestsConfigDto? = null,
)

data class LeaveRequestsConfigDto(
    val enabled: Boolean = false,
    val types: List<String> = listOf("URLOP"),
)

data class DispatchSheetReminderDto(
    val enabled: Boolean = false,
    val dueToday: Boolean = false,
    val workDate: String? = null,
    val reason: String? = null,
    val availableUntil: String? = null,
    val status: String = "not_required",
    val photo: DispatchSheetPhotoDto? = null,
    val canUpload: Boolean = false,
)

data class DispatchSheetPhotoDto(
    val id: String,
    val driverId: String,
    val workDate: String?,
    val clientRequestId: String? = null,
    val contentSha256: String? = null,
    val source: String,
    val mimeType: String?,
    val size: Long,
    val takenAt: String?,
    val latitude: Double?,
    val longitude: Double?,
    val locationAccuracyMeters: Double?,
    val createdAt: String?,
)

data class DriverSessionDto(
    val driver: DriverDto,
    val lastSyncAt: String,
)

data class NotificationPreferencesDto(
    val notifyNewRoutes: Boolean = false,
)

data class RealtimeConfigDto(
    val reverbEnabled: Boolean = false,
    val reverbAppKey: String? = null,
    val reverbWsBaseUrl: String? = null,
)

data class RoutesBucketDto(
    val today: List<DriverRouteDto> = emptyList(),
)

data class RouteResponse(
    val route: DriverRouteDto,
    val syncState: SyncStateResponse? = null,
)

data class CompleteRouteResponse(
    val ok: Boolean,
    val alreadyCompleted: Boolean,
    val message: String?,
    val completedAt: String?,
    val route: DriverRouteDto,
)

data class SyncStateResponse(
    val scopes: List<SyncScopeDto> = emptyList(),
)

data class SyncScopeDto(
    val scope: String,
    val date: String? = null,
    val routeId: String? = null,
    val version: Long,
    val checksum: String,
    val computedAt: String,
)

data class BroadcastAuthBody(
    val socket_id: String,
    val channel_name: String,
)

data class BroadcastAuthResponse(
    val auth: String,
)

data class PushTokenBody(
    val token: String,
    val platform: String = "android",
)

data class NotificationPreferencesBody(
    val notifyNewRoutes: Boolean,
)

data class LeaveRequestListResponse(
    val data: List<DriverLeaveRequestDto> = emptyList(),
)

data class LeaveCalendarResponse(
    val data: List<DriverLeaveCalendarEntryDto> = emptyList(),
)

data class LeaveRequestResponse(
    val data: DriverLeaveRequestDto,
)

data class LeaveRequestTypesResponse(
    val data: List<LeaveRequestTypeDto> = emptyList(),
)

data class LeaveRequestTypeDto(
    val value: String,
    val label: String,
)

data class CreateLeaveRequestBody(
    val dateFrom: String,
    val dateTo: String,
    val type: String,
    val note: String?,
)

data class CancelLeaveRequestBody(
    val comment: String? = null,
)

data class DriverLeaveRequestDto(
    val id: String,
    val driver: DriverDto? = null,
    val dateFrom: String?,
    val dateTo: String?,
    val type: String,
    val typeLabel: String? = null,
    val note: String? = null,
    val status: String,
    val submittedAt: String? = null,
    val decidedAt: String? = null,
    val decisionComment: String? = null,
    val events: List<DriverLeaveRequestEventDto> = emptyList(),
)

data class DriverLeaveCalendarEntryDto(
    val id: String,
    val dateFrom: String?,
    val dateTo: String?,
    val type: String,
    val typeLabel: String? = null,
    val status: String,
    val driver: DriverLeaveCalendarDriverDto,
)

data class DriverLeaveCalendarDriverDto(
    val id: String,
    val displayName: String?,
    val phoneNumber: String?,
)

data class DriverLeaveRequestEventDto(
    val id: String,
    val action: String,
    val fromStatus: String? = null,
    val toStatus: String? = null,
    val comment: String? = null,
    val createdAt: String? = null,
)

data class RealtimeStatusBody(
    val reverbStatus: String,
    val socketId: String? = null,
    val error: String? = null,
)

data class DriverRouteDto(
    val id: String,
    val routeDate: String? = null,
    val startsAt: String,
    val originName: String,
    val destinationName: String,
    val contractorName: String,
    val contractName: String?,
    val contractCode: String?,
    val relationLabel: String,
    val status: String,
    val loadingWeight: Double? = null,
    val unloadingWeight: Double? = null,
    val trackingStatus: String? = null,
    val arrivedAt: String? = null,
    val distanceKm: Double?,
    val notes: String?,
    val truck: TruckDto?,
    val completedAt: String? = null,
    val completedByDriver: DriverDto? = null,
    val originNavigation: NavigationPointDto? = null,
    val destinationNavigation: NavigationPointDto? = null,
    val photos: List<RoutePhotoDto> = emptyList(),
    val photosByStage: RoutePhotosByStageDto? = null,
)

data class RoutePhotosByStageDto(
    val loading: List<RoutePhotoDto> = emptyList(),
    val unloading: List<RoutePhotoDto> = emptyList(),
    val other: List<RoutePhotoDto> = emptyList(),
)

data class TruckDto(
    val id: String,
    val registration: String?,
    val trailerRegistration: String? = null,
    val name: String?,
)

data class NavigationPointDto(
    val id: String,
    val label: String?,
    val latitude: Double?,
    val longitude: Double?,
)

data class RoutePhotoDto(
    val id: String,
    val routeId: String,
    val clientRequestId: String? = null,
    val contentSha256: String? = null,
    val source: String,
    val stage: String = "other",
    val mimeType: String?,
    val size: Long,
    val url: String,
    val takenAt: String?,
    val latitude: Double?,
    val longitude: Double?,
    val locationAccuracyMeters: Double?,
    val createdAt: String?,
    val canDelete: Boolean = false,
    val deleteUntil: String? = null,
)

data class PhotoUploadResponse(
    val photo: RoutePhotoDto,
    val receipt: PhotoUploadReceiptDto,
)

data class PhotoUploadReceiptDto(
    val clientRequestId: String,
    val serverPhotoId: String,
    val contentSha256: String,
    val storedAt: String?,
)

data class StartRouteBody(
    val clientActionId: String,
    val loadingWeight: Double,
    val occurredAt: String,
    val photoClientRequestIds: List<String>,
)

data class FinishRouteBody(
    val clientActionId: String,
    val unloadingWeight: Double,
    val occurredAt: String,
    val photoClientRequestIds: List<String>,
)

data class RouteActionResponse(
    val ok: Boolean,
    val alreadyProcessed: Boolean,
    val route: DriverRouteDto,
)

data class RoutePointBatchBody(
    val clientBatchId: String,
    val points: List<RoutePointDto>,
)

data class RoutePointDto(
    val clientPointId: String,
    val trip_id: String,
    val driver_id: String,
    val lat: Double,
    val lon: Double,
    val accuracy: Double,
    val speed: Double?,
    val bearing: Double?,
    val timestamp: Long,
    val battery: Int?,
    val charging: Boolean,
)

data class RoutePointsResponse(
    val ok: Boolean,
    val stored: Int,
    val progress: Double?,
    val remainingDistanceMeters: Int?,
    val arrived: Boolean,
    val offRoute: Boolean,
    val routeVersion: Long?,
)

data class DispatchSheetUploadResponse(
    val photo: DispatchSheetPhotoDto,
    val reminder: DispatchSheetReminderDto,
    val receipt: DispatchSheetUploadReceiptDto,
)

data class DispatchSheetUploadReceiptDto(
    val clientRequestId: String,
    val serverPhotoId: String,
    val contentSha256: String,
    val storedAt: String?,
)
