<?php
defined('BASEPATH') or exit('No direct script access allowed');

/**
 * @property Event_enrollment_item_reception_model $Event_enrollment_item_reception_model
 */
class Attendance extends MY_ApiController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function save()
    {
        $this->is_post();
        $this->is_json();

        $this->load->model('Event_enrollment_item_model');
        $this->Event_enrollment_item_model->setTenantNo($this->json['tenant_no'], true);

        switch ($this->json['type']) {
            case 'in':
            case 'out':
                $res = $this->Event_enrollment_item_model->{$this->json['type']}($this->json['item_ids'], $this->json['auto_attendout'] == 1);
                break;
            default:
                // absent, erase
                $res = $this->Event_enrollment_item_model->{$this->json['type']}($this->json['item_ids']);
                break;
        }

        echo $this->respond($res);
    }

    // public function reception_in()
    // {
    //     $this->is_post();
    //     $this->is_json();

    //     $this->load->model('Event_enrollment_item_reception_model');
    //     $this->Event_enrollment_item_reception_model->setTenantNo($this->json['tenant_no'], true);
    //     $res = $this->Event_enrollment_item_reception_model->in($this->json['student_no']);

    //     $this->Event_enrollment_item_reception_model->trigger_push_notification($res['id']);
    //     echo $this->respond($res);
    // }

    // public function reception_out()
    // {
    //     $this->is_post();
    //     $this->is_json();

    //     $this->load->model('Event_enrollment_item_reception_model');
    //     $this->Event_enrollment_item_reception_model->setTenantNo($this->json['tenant_no'], true);
    //     $res = $this->Event_enrollment_item_reception_model->out($this->json['student_no']);

    //     $this->Event_enrollment_item_reception_model->trigger_push_notification($res['id'], false);
    //     echo $this->respond($res);
    // }
}
