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,
    @SerializedName("accrual_period") val accrualPeriod: String = "yearly",
    @SerializedName("policy_carry_forward") val policyCarryForward: Int = 0,
    @SerializedName("policy_encashable") val policyEncashable: Int = 0
)
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)

data class PayslipListWrapper(val payslips: List<PayslipListItem>)
data class PayslipListItem(
    val month: Int, val year: Int,
    @SerializedName("gross_salary") val grossSalary: Float,
    @SerializedName("net_salary") val netSalary: Float,
    @SerializedName("total_deductions") val totalDeductions: Float,
    val status: String?
)

data class PayslipDetailWrapper(
    val payslip: PayslipDetail,
    val employee: PayslipEmployee,
    val bank: PayslipBank?,
    val company: PayslipCompany?,
    val attendance: PayslipAttendance?,
    val month: Int, val year: Int
)
data class PayslipEmployee(
    @SerializedName("first_name") val firstName: String,
    @SerializedName("last_name") val lastName: String,
    @SerializedName("employee_id") val employeeId: String,
    val designation: String?,
    val department: String?,
    @SerializedName("uan_number") val uanNumber: String?,
    @SerializedName("pan_number") val panNumber: String?
)
data class PayslipBank(
    @SerializedName("bank_name") val bankName: String?,
    @SerializedName("account_number") val accountNumber: String?
)
data class PayslipCompany(
    @SerializedName("company_name") val companyName: String?,
    val address: String?,
    @SerializedName("logo_url") val logoUrl: String?
)
data class PayslipAttendance(
    @SerializedName("present_days") val presentDays: Float?,
    @SerializedName("absent_days") val absentDays: Float?,
    @SerializedName("half_days") val halfDays: Float?,
    @SerializedName("leave_days") val leaveDays: Float?,
    @SerializedName("week_off_days") val weekOffDays: Int?,
    val holidays: Int?,
    @SerializedName("lop_days") val lopDays: Float?,
    @SerializedName("od_days") val odDays: Float?
)
data class PayslipDetail(
    val basic: Float, val hra: Float, val da: Float,
    val conveyance: Float, val medical: Float,
    @SerializedName("special_allowance") val specialAllowance: Float,
    val lta: Float?, val incentive: Float?,
    val bonus: Float?, val arrears: Float?,
    @SerializedName("other_earnings") val otherEarnings: Float?,
    @SerializedName("gross_salary") val grossSalary: Float,
    @SerializedName("pf_employee") val pfEmployee: Float,
    @SerializedName("esi_employee") val esiEmployee: Float,
    @SerializedName("professional_tax") val professionalTax: Float,
    @SerializedName("income_tax") val incomeTax: Float,
    @SerializedName("advance_recovery") val advanceRecovery: Float?,
    @SerializedName("loan_recovery") val loanRecovery: Float?,
    @SerializedName("total_deductions") val totalDeductions: Float,
    @SerializedName("net_salary") val netSalary: Float,
    @SerializedName("present_days") val presentDays: Float?,
    @SerializedName("lop_days") val lopDays: 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
)
