package com.seyalix.hr.api

import com.seyalix.hr.models.*
import retrofit2.Response
import retrofit2.http.*

interface ApiService {

    // ── App Update ───────────────────────────────────────────
    // Public endpoint (no auth token needed) — checked on every app
    // launch so we can show an "Update Available" popup, the same way
    // a phone shows a system-update popup.
    @GET("?action=app_version")
    suspend fun getAppVersion(): Response<ApiResponse<AppVersionData>>

    // ── Auth ─────────────────────────────────────────────────
    @POST("?action=login")
    suspend fun login(@Body body: Map<String, String>): Response<ApiResponse<LoginData>>

    @POST("?action=logout")
    suspend fun logout(): Response<ApiResponse<Any>>

    // ── Dashboard ─────────────────────────────────────────────
    @GET("?action=dashboard")
    suspend fun getDashboard(): Response<ApiResponse<DashboardData>>

    // ── Attendance ────────────────────────────────────────────
    @POST("?action=check_in")
    suspend fun checkIn(@Body body: Map<String, String>): Response<ApiResponse<CheckInData>>

    @POST("?action=check_out")
    suspend fun checkOut(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @GET("?action=attendance_history")
    suspend fun getAttendanceHistory(
        @Query("month") month: Int,
        @Query("year") year: Int
    ): Response<ApiResponse<List<AttendanceRecord>>>

    @GET("?action=holidays")
    suspend fun getHolidays(@Query("year") year: Int): Response<ApiResponse<List<Holiday>>>

    // ── Permission ────────────────────────────────────────────
    @POST("?action=apply_permission")
    suspend fun applyPermission(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @GET("?action=my_permissions")
    suspend fun getMyPermissions(): Response<ApiResponse<List<PermissionRecord>>>

    // ── Late Regularization ───────────────────────────────────
    @POST("?action=apply_late_regularization")
    suspend fun applyLateRegularization(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @GET("?action=my_late_regularizations")
    suspend fun getMyLateRegularizations(): Response<ApiResponse<List<LateMarkRecord>>>




    // ── Muster Modification ───────────────────────────────────
    @POST("?action=apply_muster_modification")
    suspend fun applyMusterModification(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @GET("?action=my_muster_modifications")
    suspend fun getMyMusterModifications(): Response<ApiResponse<List<MusterModificationRecord>>>

    @GET("?action=pending_muster_modifications")
    suspend fun getPendingMusterModifications(): Response<ApiResponse<List<MusterModificationRecord>>>

    @POST("?action=approve_muster_modification")
    suspend fun approveMusterModification(@Body body: Map<String, String>): Response<ApiResponse<Any>>
    // ── Leave ─────────────────────────────────────────────────
    @GET("?action=leave_balance")
    suspend fun getLeaveBalance(): Response<ApiResponse<List<LeaveBalance>>>

    @POST("?action=apply_leave")
    suspend fun applyLeave(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @GET("?action=leave_applications")
    suspend fun getLeaveApplications(): Response<ApiResponse<List<LeaveApplication>>>

    @GET("?action=leave_types")
    suspend fun getLeaveTypes(): Response<ApiResponse<List<LeaveType>>>

    // ── On Duty ──────────────────────────────────────────────
    @GET("?action=my_on_duty")
    suspend fun getMyOnDuty(): Response<ApiResponse<List<OnDutyRequest>>>

    @POST("?action=apply_on_duty")
    suspend fun applyOnDuty(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @GET("?action=pending_on_duty")
    suspend fun getPendingOnDuty(): Response<ApiResponse<List<OnDutyRequest>>>

    @POST("?action=approve_on_duty")
    suspend fun approveOnDuty(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    // ── Manager: Team attendance ───────────────────────────────
    @GET("?action=team_attendance")
    suspend fun getTeamAttendance(@Query("date") date: String): Response<ApiResponse<List<TeamAttendanceSummary>>>

    // ── Approvals: Head (manager) ──────────────────────────────
    @GET("?action=pending_approvals")
    suspend fun getPendingApprovals(): Response<ApiResponse<List<LeaveApplication>>>

    @POST("?action=approve_leave")
    suspend fun approveLeave(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @GET("?action=pending_permissions")
    suspend fun getPendingPermissions(): Response<ApiResponse<List<PermissionRecord>>>

    @POST("?action=approve_permission")
    suspend fun approvePermission(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @GET("?action=pending_late_marks")
    suspend fun getPendingLateMarks(): Response<ApiResponse<List<LateMarkRecord>>>

    @POST("?action=approve_late_mark")
    suspend fun approveLateMarks(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    // ── Reports (head/hr) ─────────────────────────────────────
    @GET("?action=team_report")
    suspend fun getTeamReport(
        @Query("month") month: Int,
        @Query("year") year: Int
    ): Response<ApiResponse<List<Map<String, Any>>>>

    // ── Management / Senior – all-org pending ─────────────────
    @GET("?action=all_pending_approvals")
    suspend fun getAllPendingApprovals(): Response<ApiResponse<Map<String, Any>>>

    @POST("?action=management_approve")
    suspend fun managementApprove(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    // Lightweight poll for "did anything new come in for me to approve?" —
    // used to drive the badge dot + local notification without pulling the
    // full pending lists on every check.
    @GET("?action=pending_counts")
    suspend fun getPendingCounts(): Response<ApiResponse<PendingCounts>>

    // ── Notifications ──────────────────────────────────────────
    @GET("?action=get_notifications")
    suspend fun getNotifications(): Response<ApiResponse<List<AppNotification>>>

    @GET("?action=unread_notification_count")
    suspend fun getUnreadNotificationCount(): Response<ApiResponse<UnreadCount>>

    @POST("?action=mark_notification_read")
    suspend fun markNotificationRead(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @POST("?action=mark_notification_unread")
    suspend fun markNotificationUnread(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @POST("?action=mark_all_read")
    suspend fun markAllNotificationsRead(@Body body: Map<String, String>): Response<ApiResponse<Any>>

    @POST("?action=mark_all_unread")
    suspend fun markAllNotificationsUnread(@Body body: Map<String, String>): Response<ApiResponse<Any>>
}
