<?php 
    include_once __dir__ .  '/../core/LogEvent.php';

    class CompanyEmployee extends Core {

        function save() {

            $company_id = $_POST['companyId'];
            $firstname = $_POST['firstname'];
            $lastname = $_POST['lastname'];
            $password = $_POST['password'];
            $email = $_POST['email'];

            $sql = "INSERT leads 
                SET firstname = :firstname, 
                lastname = :lastname, 
                email = :email,
                is_published = 1, 
                date_added = NOW(), 
                date_identified = NOW(), 
                account_type = 'company', 
                password = :password,
                company_employee_id = :company_employee_id";
            $stmt = parent::$conn->prepare($sql);
            $stmt->execute([
                ':firstname' => $firstname,
                ':lastname' => $lastname,
                ':email' => $email,
                ':password' => $password,                
                ':company_employee_id' => $company_id
            ]);

            $insert_id = parent::$conn->lastInsertId();
            $title = "Acessou o fit cultural compartilhado";
            $url = "";            
            LogEvent::log($insert_id, $company_id, $url, $title, LogEvent::VIEW_SHARED_FIT_CULTURAL, true);

            return [ 'type' => 'OK' ];
            
        }

        function update() {

            $company_id = $_POST['companyId'];
            $lead_id = $_POST['id'];

            $sql = "UPDATE leads SET company_employee_id = :company_id WHERE id = :id";
            $stmt = parent::$conn->prepare($sql);
            $stmt->execute([
                ':company_id' => $company_id,
                ':id' => $lead_id
            ]);

            return [ 'type' => 'OK' ];
            
        }

    }