<?php
namespace App\Services;

use App\Models\AuditLog;

class AuditService {
    
    protected $auditLog;
    
    public function __construct() {
        $this->auditLog = new AuditLog();
    }
    
    /**
     * Log login activity
     */
    public function logLogin($username, $success) {
        return $this->auditLog->log(
            $success ? 'LOGIN' : 'LOGIN_FAILED',
            'users',
            null,
            null,
            ['username' => $username]
        );
    }
    
    /**
     * Log logout activity
     */
    public function logLogout() {
        return $this->auditLog->log('LOGOUT');
    }
    
    /**
     * Log create action
     */
    public function logCreate($table, $record_id, $data) {
        return $this->auditLog->log(
            'CREATE',
            $table,
            $record_id,
            null,
            $data
        );
    }
    
    /**
     * Log update action
     */
    public function logUpdate($table, $record_id, $old_data, $new_data) {
        return $this->auditLog->log(
            'UPDATE',
            $table,
            $record_id,
            $old_data,
            $new_data
        );
    }
    
    /**
     * Log delete action
     */
    public function logDelete($table, $record_id, $data) {
        return $this->auditLog->log(
            'DELETE',
            $table,
            $record_id,
            $data,
            null
        );
    }
    
    /**
     * Log approval action
     */
    public function logApproval($person_id, $status, $remarks) {
        return $this->auditLog->log(
            $status === 'Approved' ? 'APPROVE' : 'REJECT',
            'application_status',
            $person_id,
            null,
            ['status' => $status, 'remarks' => $remarks]
        );
    }
    
    /**
     * Log view action
     */
    public function logView($table, $record_id) {
        return $this->auditLog->log(
            'VIEW',
            $table,
            $record_id,
            null,
            null
        );
    }
}