package com.seyalix.hr.models

import com.google.gson.annotations.SerializedName

// ── Generic API Response ─────────────────────────────────────
data class ApiResponse<T>(
    val success: Boolean,
    val message: String,
    val data: T?,
    val timestamp: Long
)

// ── Auth ─────────────────────────────────────────────────────
data class LoginRequest(val username: String, val password: String)
data class LoginData(
    val token: String,
    @SerializedName("expires_in") val expiresIn: Int,
    @SerializedName("employee_id") val employeeId: Int,
    @SerializedName("emp_code") val empCode: String,
    val name: String,
    val role: String,
    val department: String?,
    val designation: String?,
    val photo: String?
)

// ── Dashboard ────────────────────────────────────────────────
data class DashboardData(
    @SerializedName("today_status") val todayStatus: String,
    @SerializedName("check_in") val checkIn: String?,
    @SerializedName("check_out") val checkOut: String?,
    @SerializedName("leave_balances") val leaveBalances: List<LeaveBalance>,
    @SerializedName("pending_leaves") val pendingLeaves: Int,
    @SerializedName("latest_payslip") val latestPayslip: PayslipSummary?,
    val notices: List<Notice>,
    @SerializedName("pending_approvals_count") val pendingApprovalsCount: Int = 0
)

// ── Attendance ───────────────────────────────────────────────
data class AttendanceRecord(
    val id: Int,
    val date: String,
    @SerializedName("check_in") val checkIn: String?,
    @SerializedName("check_out") val checkOut: String?,
    val status: String,
    @SerializedName("working_hours") val workingHours: String?,
    @SerializedName("late_minutes") val lateMinutes: Int = 0
)
data class CheckInData(
    @SerializedName("check_in_time") val checkInTime: String,
    @SerializedName("attendance_id") val attendanceId: Int
)

// ── Permission ───────────────────────────────────────────────
data class PermissionRecord(
    val id: Int,
    @SerializedName("permission_date") val permissionDate: String,
    @SerializedName("from_time") val fromTime: String,
    @SerializedName("to_time") val toTime: String,
    @SerializedName("duration_minutes") val durationMinutes: Int,
    val reason: String,
    val status: String,
    @SerializedName("approved_by_name") val approvedByName: String?,
    val remarks: String?,
    @SerializedName("first_name") val firstName: String? = null,
    @SerializedName("last_name") val lastName: String? = null,
    @SerializedName("emp_code") val empCode: String? = null,
    @SerializedName("employee_id") val employeeId: Int? = null
)

// ── Late Mark ─────────────────────────────────────────────────
data class LateMarkRecord(
    val id: Int,
    val date: String,
    @SerializedName("late_minutes") val lateMinutes: Int,
    val reason: String,
    val status: String,
    @SerializedName("approved_by_name") val approvedByName: String?,
    @SerializedName("first_name") val firstName: String? = null,
    @SerializedName("last_name") val lastName: String? = null,
    @SerializedName("emp_code") val empCode: String? = null,
    @SerializedName("employee_id") val employeeId: Int? = null
)

// ── Leave ─────────────────────────────────────────────────────
data class LeaveBalance(
    val code: String,
    val name: String,
    val allocated: Float,
    val used: Float,
    val available: Float
)
data class LeaveApplication(
    val id: Int,
    @SerializedName("leave_type_id") val leaveTypeId: Int,
    @SerializedName("lt_name") val leaveTypeName: String?,
    @SerializedName("start_date") val startDate: String,
    @SerializedName("end_date") val endDate: String,
    val days: Float,
    val reason: String,
    val status: String,
    @SerializedName("applied_on") val appliedOn: String,
    @SerializedName("approved_by_name") val approvedByName: String?,
    val remarks: String?,
    @SerializedName("first_name") val firstName: String? = null,
    @SerializedName("last_name") val lastName: String? = null,
    @SerializedName("emp_code") val empCode: String? = null,
    @SerializedName("employee_id") val employeeId: Int? = null
)
data class LeaveType(val id: Int, val name: String, val code: String)

// ── On Duty ──────────────────────────────────────────────────
// Matches the JSON shape returned by ?action=my_on_duty (employee's own
// requests) and ?action=pending_on_duty (a manager's team requests) —
// both return rows from the on_duty_requests table (see
// migration_on_duty.sql / migration_on_duty_add_time.sql).
data class OnDutyRequest(
    val id: Int,
    @SerializedName("employee_id") val employeeId: Int? = null,
    @SerializedName("from_date") val startDate: String,
    @SerializedName("to_date") val endDate: String,
    @SerializedName("is_full_day") val isFullDay: Int = 1,
    @SerializedName("from_time") val fromTime: String? = null,
    @SerializedName("to_time") val toTime: String? = null,
    val days: Float = 1f,
    val purpose: String,
    val location: String? = null,
    val reason: String? = null,
    val status: String,
    val remarks: String? = null,
    @SerializedName("first_name") val firstName: String? = null,
    @SerializedName("last_name") val lastName: String? = null,
    @SerializedName("emp_code") val empCode: String? = null
)

// ── Holiday ───────────────────────────────────────────────────
data class Holiday(
    val name: String,
    val date: String,
    @SerializedName("is_national") val isNational: Int = 0
)

// ── Team ─────────────────────────────────────────────────────
data class TeamAttendanceSummary(
    @SerializedName("employee_id") val employeeId: Int,
    @SerializedName("emp_code") val empCode: String,
    @SerializedName("first_name") val firstName: String,
    @SerializedName("last_name") val lastName: String,
    val status: String,
    @SerializedName("check_in") val checkIn: String?,
    @SerializedName("check_out") val checkOut: String?
)

// ── Pending approval badge/notification polling ────────────────
data class PendingCounts(
    val leave: Int,
    val permission: Int,
    val late: Int,
    val muster: Int,
    val total: Int
)

// ── Payslip ───────────────────────────────────────────────────
data class PayslipSummary(val month: Int, val year: Int, @SerializedName("net_salary") val netSalary: Float)

// ── Notice ────────────────────────────────────────────────────
data class Notice(val id: Int, val title: String, val category: String, @SerializedName("published_at") val publishedAt: String)






data class MusterModificationRecord(
    val id: Int,
    val date: String,
    val time: String?,
    @SerializedName("issue_type") val issueType: String,
    val reason: String?,
    val status: String,
    @SerializedName("remarks") val remarks: String? = null,
    @SerializedName("first_name") val firstName: String? = null,
    @SerializedName("last_name") val lastName: String? = null,
    @SerializedName("emp_code") val empCode: String? = null,
    @SerializedName("employee_id") val employeeId: Int? = null
)

// ── Notifications ─────────────────────────────────────────────
data class AppNotification(
    val id: Int,
    @SerializedName("employee_id") val employeeId: Int,
    val title: String,
    val message: String,
    val type: String,
    @SerializedName("ref_id") val refId: Int?,
    @SerializedName("is_read") val isRead: Int,
    @SerializedName("created_at") val createdAt: String
)

data class UnreadCount(val count: Int)

// ── App Update ───────────────────────────────────────────────
// Returned by ?action=app_version (public, no auth needed — checked
// before/alongside login so even a logged-out user on an old build
// gets told to update). Compare latestVersionCode against
// BuildConfig.VERSION_CODE to decide whether to show the update popup.
data class AppVersionData(
    @SerializedName("latest_version_code") val latestVersionCode: Int,
    @SerializedName("latest_version_name") val latestVersionName: String,
    val message: String,
    @SerializedName("update_url") val updateUrl: String
)
