<?php

namespace CouponsPlus\App\Conditions\BuiltIn\Conditions;

use CouponsPlus\App\Conditions\Condition;
use CouponsPlus\Original\Collections\Collection;
use CouponsPlus\Original\Collections\Mapper\Types;

#[\AllowDynamicProperties]
Class CustomerType extends Condition
{
    const TYPE = 'CustomerType';
    
    static public function getName() : string
    {
        return __('Guest/Logged In', 'coupons-plus-for-woocommerce');
    }

    static public function getDescription() : string
    {
        return 'This condition may be used to restrict offers to customer who are guests or logged in to their accounts.';
    }
    
    static public function getUseCases(): Collection
    {
        return new Collection([
            __('Restrict offers to customers with an existing account', 'coupons-plus-for-woocommerce'),
        ]);  
    } 

    public static function getOptions() : Collection
    {
        return new Collection([
            'type' => Types::STRING()->withDefault('account') // aka a customer with an account
                                     ->allowed([
                                        __('With An Account', 'coupons-plus-for-woocommerce') => 'account',
                                        __('Guest', 'coupons-plus-for-woocommerce') => 'guest',
                                    ])
        ]);   
    }
 
    protected function test() : bool
    {
        $isLoggedIn = is_user_logged_in();

        return $this->options->type->is('account') ? $isLoggedIn : !$isLoggedIn;
    }
}