<?php

/**
 * @package: EGPS - Easy Sell for Google Photo
 */

if(!defined('ABSPATH')){
    exit; // Exit if accessed directly
}

class EgpsCustomers{

    private static $tablename = "egps_customers";

    /*
    public static function egps_createCustomer($data = array()){
        
        $def_pass = substr(md5(Egps::egps_datenow(), 0, 5));

        $data['customer_pass'] = password_hash($def_pass, PASSWORD_DEFAULT);

        EgpsDatabase::egps_insert_to_db(self::$tablename, $data);


        // check if customer added or not
        $newcustomer = EgpsDatabase::egps_get_row(self::$tablename, "customer_email", $data["customer_email"]);
        
        // send email about the registration
        if( !filter_var( $data["customer_email"], FILTER_VALIDATE_EMAIL ) || ($newcustomer == null)) {
            self::egps_send_registration_email($data["customer_email"], $def_pass);
        }

    }
    */

    public static function egps_validateCustomer($email, $pass){

        $hashed_password = password_hash($pass, PASSWORD_DEFAULT);

        $customer = EgpsDatabase::egps_get_row(self::$tablename, "customer_email", $email);

        if($customer != null){
            if($customer['customer_pass'] == $hashed_password){
                return true;
            }else{
                return false;
            }
        }

        return false;
    }

    public static function egps_customer_unsubscribe($email){
        
        $customer = EgpsDatabase::egps_get_row(self::$tablename, "customer_email", $email);
        
        if($customer != null){
            $newdata = array("customer_email_enabled" => "false");

            $where = array("customer_email" => $email);


            EgpsDatabase::egps_update_db_table(self::$tablename, $newdata, $where);

        }

    }


}