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

class Login extends MY_ApiController
{
    public function __construct()
    {
        parent::__construct();
    }

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

        $username = $this->json['username'];
        $password = $this->json['password'];

        try {
            $this->load->model('Teacher_model');
            $data = $this->Teacher_model->login($username, $password);
            echo $this->respond($data);
        } catch (Exception $e) {
            echo $this->respond(['message' => $e->getMessage()], 400);
        }
    }

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

        $username = $this->json['username'];
        $password = $this->json['password'];
        $fcmToken = $this->json['fcm_token'];

        try {
            $this->load->model('Parent_model');
            $data = $this->Parent_model->login($username, $password);

            $this->Parent_model->update_fcm_token($fcmToken, $data['userinfo']['id']);
            echo $this->respond($data);
        } catch (Exception $e) {
            echo $this->respond(['message' => $e->getMessage()], 400);
        }
    }
}
